diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java index 09604493..e62178c4 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java @@ -642,8 +642,15 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera videoResult.videoBitRate = mVideoBitRate; videoResult.audioBitRate = mAudioBitRate; - // Initialize the media recorder - mCamera.unlock(); + // Unlock the camera and start recording. + try { + mCamera.unlock(); + } catch (Exception e) { + // If this failed, we are unlikely able to record the video. + // Dispatch an error. + onVideoResult(null); + return; + } mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this, mCamera, mCameraId); mVideoRecorder.start(); } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java index 86e7b0e1..94ce80ec 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java @@ -109,6 +109,7 @@ class FullVideoRecorder extends VideoRecorder { mMediaRecorder.stop(); } catch (Exception e) { // This can happen if stopVideo() is called right after takeVideo(). We don't care. + mResult = null; LOG.w("stop:", "Error while closing media recorder. Swallowing", e); } mMediaRecorder.release();