pull/471/head
Mattia Iavarone 6 years ago
parent 52cf46cc3d
commit 1fef9d28cf
  1. 2
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoRecorderTest.java
  2. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  3. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/FullVideoRecorder.java
  4. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java
  5. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java

@ -28,7 +28,7 @@ public class VideoRecorderTest extends BaseTest {
}; };
recorder.start(); recorder.start();
recorder.stop(); recorder.stop();
Mockito.verify(listener, Mockito.times(1)).onVideoResult(result); Mockito.verify(listener, Mockito.times(1)).onVideoResult(result, );
assertNull(recorder.mListener); assertNull(recorder.mListener);
assertNull(recorder.mResult); assertNull(recorder.mResult);
} }

@ -336,7 +336,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
return; return;
} }
LOG.e("Error inside the onError callback.", error); LOG.e("Internal Camera1 error.", error);
Exception runtime = new RuntimeException(CameraLogger.lastMessage); Exception runtime = new RuntimeException(CameraLogger.lastMessage);
int reason; int reason;
switch (error) { switch (error) {
@ -646,13 +646,13 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
// Video recording stuff. // Video recording stuff.
@Override @Override
public void onVideoResult(@Nullable VideoResult result) { public void onVideoResult(@Nullable VideoResult result, @Nullable Exception exception) {
mVideoRecorder = null; mVideoRecorder = null;
if (result != null) { if (result != null) {
mCameraCallbacks.dispatchOnVideoTaken(result); mCameraCallbacks.dispatchOnVideoTaken(result);
} else { } else {
// Something went wrong, lock the camera again. // Something went wrong, lock the camera again.
mCameraCallbacks.dispatchError(new CameraException(CameraException.REASON_VIDEO_FAILED)); mCameraCallbacks.dispatchError(new CameraException(exception, CameraException.REASON_VIDEO_FAILED));
mCamera.lock(); mCamera.lock();
} }
} }
@ -689,7 +689,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
} catch (Exception e) { } catch (Exception e) {
// If this failed, we are unlikely able to record the video. // If this failed, we are unlikely able to record the video.
// Dispatch an error. // Dispatch an error.
onVideoResult(null); onVideoResult(null, e);
return; return;
} }
mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this, mVideoRecorder = new FullVideoRecorder(videoResult, Camera1.this,

@ -104,7 +104,9 @@ class FullVideoRecorder extends VideoRecorder {
mMediaRecorder.prepare(); mMediaRecorder.prepare();
mMediaRecorder.start(); mMediaRecorder.start();
} catch (Exception e) { } catch (Exception e) {
LOG.w("stop:", "Error while starting media recorder.", e);
mResult = null; mResult = null;
mError = e;
stop(); stop();
} }
} }
@ -115,9 +117,12 @@ class FullVideoRecorder extends VideoRecorder {
try { try {
mMediaRecorder.stop(); mMediaRecorder.stop();
} catch (Exception e) { } catch (Exception e) {
// This can happen if stopVideo() is called right after takeVideo(). We don't care. LOG.w("stop:", "Error while closing media recorder.", e);
// This can happen if stopVideo() is called right after takeVideo() (in which case we don't care)
// Or when prepare()/start() have failed for some reason and we are not allowed to call stop.
// Make sure we don't override the error if one exists already.
mResult = null; mResult = null;
LOG.w("stop:", "Error while closing media recorder. Swallowing", e); if (mError == null) mError = e;
} }
mMediaRecorder.release(); mMediaRecorder.release();
if (mController != null) { if (mController != null) {

@ -124,7 +124,9 @@ class SnapshotVideoRecorder extends VideoRecorder implements GlCameraPreview.Ren
// If something failed, undo the result, since this is the mechanism // If something failed, undo the result, since this is the mechanism
// to notify Camera1 about this. // to notify Camera1 about this.
if (e != null) { if (e != null) {
LOG.e("Error onEncoderStop", e);
mResult = null; mResult = null;
mError = e;
} else { } else {
if (stopReason == MediaEncoderEngine.STOP_BY_MAX_DURATION) { if (stopReason == MediaEncoderEngine.STOP_BY_MAX_DURATION) {
mResult.endReason = VideoResult.REASON_MAX_DURATION_REACHED; mResult.endReason = VideoResult.REASON_MAX_DURATION_REACHED;

@ -12,6 +12,7 @@ abstract class VideoRecorder {
/* tests */ VideoResult mResult; /* tests */ VideoResult mResult;
/* tests */ VideoResultListener mListener; /* tests */ VideoResultListener mListener;
protected Exception mError;
VideoRecorder(@NonNull VideoResult stub, @Nullable VideoResultListener listener) { VideoRecorder(@NonNull VideoResult stub, @Nullable VideoResultListener listener) {
mResult = stub; mResult = stub;
@ -25,14 +26,15 @@ abstract class VideoRecorder {
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
protected void dispatchResult() { protected void dispatchResult() {
if (mListener != null) { if (mListener != null) {
mListener.onVideoResult(mResult); mListener.onVideoResult(mResult, mError);
mListener = null; mListener = null;
mResult = null; mResult = null;
mError = null;
} }
} }
interface VideoResultListener { interface VideoResultListener {
void onVideoResult(@Nullable VideoResult result); void onVideoResult(@Nullable VideoResult result, @Nullable Exception exception);
} }
} }

Loading…
Cancel
Save