Better video error handling

pull/360/head
Mattia Iavarone 6 years ago
parent 1b5a20b034
commit 97c839af87
  1. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 1
      cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java

@ -642,8 +642,15 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
videoResult.videoBitRate = mVideoBitRate; videoResult.videoBitRate = mVideoBitRate;
videoResult.audioBitRate = mAudioBitRate; videoResult.audioBitRate = mAudioBitRate;
// Initialize the media recorder // Unlock the camera and start recording.
mCamera.unlock(); 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 = new FullVideoRecorder(videoResult, Camera1.this, mCamera, mCameraId);
mVideoRecorder.start(); mVideoRecorder.start();
} }

@ -109,6 +109,7 @@ class FullVideoRecorder extends VideoRecorder {
mMediaRecorder.stop(); mMediaRecorder.stop();
} catch (Exception e) { } catch (Exception e) {
// This can happen if stopVideo() is called right after takeVideo(). We don't care. // 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); LOG.w("stop:", "Error while closing media recorder. Swallowing", e);
} }
mMediaRecorder.release(); mMediaRecorder.release();

Loading…
Cancel
Save