@@ -61,6 +61,8 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
6161 private var mIsFocusing = false
6262 private var autoFocusHandler = Handler ()
6363
64+ var isWaitingForTakePictureCallback = false
65+
6466 constructor (context: Context ) : super (context)
6567
6668 constructor (activity: MainActivity , surfaceView: SurfaceView , previewListener: PreviewListener ) : super (activity) {
@@ -275,6 +277,15 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
275277 val selectedResolution = getSelectedResolution()
276278 mParameters!! .setPictureSize(selectedResolution.width, selectedResolution.height);
277279
280+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
281+ mCamera!! .enableShutterSound(false )
282+ }
283+
284+ mRotationAtCapture = MainActivity .mLastHandledOrientation
285+ mCamera!! .parameters = mParameters
286+ isWaitingForTakePictureCallback = true
287+ mCamera!! .takePicture(null , null , takePictureCallback)
288+
278289 if (config.isSoundEnabled) {
279290 val audioManager = context.getSystemService(Context .AUDIO_SERVICE ) as AudioManager
280291 val volume = audioManager.getStreamVolume(AudioManager .STREAM_SYSTEM )
@@ -283,20 +294,13 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
283294 mp?.start()
284295 }
285296 }
286-
287- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
288- mCamera!! .enableShutterSound(false )
289- }
290-
291- mRotationAtCapture = MainActivity .mLastHandledOrientation
292- mCamera!! .parameters = mParameters
293- mCamera!! .takePicture(null , null , takePictureCallback)
294297 }
295298 mCanTakePicture = false
296299 mIsFocusing = false
297300 }
298301
299302 private val takePictureCallback = Camera .PictureCallback { data, cam ->
303+ isWaitingForTakePictureCallback = false
300304 if (config.isShowPreviewEnabled) {
301305 mIsPreviewShown = true
302306 if (! config.wasPhotoPreviewHintShown) {
0 commit comments