implement camera exceptions for all existing exceptions in Camera1

pull/59/merge^2
Tim H 8 years ago
parent 758f815aa1
commit d9141b6cdf
  1. 19
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  3. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraException.java

@ -75,8 +75,9 @@ class Camera1 extends CameraController {
try { try {
setup(); setup();
} catch (Exception e) { } catch (Exception e) {
LOG.w("onSurfaceAvailable:", "Exception while binding camera to preview.", e); CameraException cameraException = new CameraUnavailableException(
throw new RuntimeException(e); "onSurfaceAvailable: Exception while binding camera to preview.", e);
mCameraCallbacks.onError(cameraException);
} }
} }
}); });
@ -394,7 +395,9 @@ class Camera1 extends CameraController {
if (mIsCapturingVideo) { if (mIsCapturingVideo) {
// TODO: actually any call to getParameters() could fail while recording a video. // TODO: actually any call to getParameters() could fail while recording a video.
// See. https://stackoverflow.com/questions/14941625/correct-handling-of-exception-getparameters-failed-empty-parameters // See. https://stackoverflow.com/questions/14941625/correct-handling-of-exception-getparameters-failed-empty-parameters
throw new IllegalStateException("Can't change video quality while recording a video."); CameraException cameraException = new CameraConfigurationFailedException("Can't change video quality while recording a video.");
mCameraCallbacks.onError(cameraException);
return;
} }
mVideoQuality = videoQuality; mVideoQuality = videoQuality;
@ -606,14 +609,20 @@ class Camera1 extends CameraController {
mMediaRecorder.start(); mMediaRecorder.start();
return true; return true;
} catch (Exception e) { } catch (Exception e) {
LOG.e("Error while starting MediaRecorder. Swallowing.", e); CameraException cameraException =
new CapturingVideoFailedException("Error while starting MediaRecorder. " +
"Swallowing.", e);
mCameraCallbacks.onError(cameraException);
mVideoFile = null; mVideoFile = null;
mCamera.lock(); mCamera.lock();
endVideo(); endVideo();
return false; return false;
} }
} else { } else {
throw new IllegalStateException("Can't record video while session type is picture"); CameraException cameraException =
new CapturingVideoFailedException("Can't record video while session type is picture");
mCameraCallbacks.onError(cameraException);
return false;
} }
} }

@ -99,7 +99,7 @@ abstract class CameraController implements CameraPreview.SurfaceCallback {
} catch (Exception e) { } catch (Exception e) {
CameraException cameraException = CameraException cameraException =
new CameraException("Error while starting the camera engine.", e); new CameraUnavailableException("Error while starting the camera engine.", e);
mCameraCallbacks.onError(cameraException); mCameraCallbacks.onError(cameraException);
} }
} }
@ -124,7 +124,7 @@ abstract class CameraController implements CameraPreview.SurfaceCallback {
} catch (Exception e) { } catch (Exception e) {
CameraException cameraException = CameraException cameraException =
new CameraException("Error while stopping the camera engine.", e); new CameraUnavailableException("Error while stopping the camera engine.", e);
mCameraCallbacks.onError(cameraException); mCameraCallbacks.onError(cameraException);
} }
} }
@ -173,7 +173,7 @@ abstract class CameraController implements CameraPreview.SurfaceCallback {
} catch (Exception e) { } catch (Exception e) {
CameraException cameraException = CameraException cameraException =
new CameraException("Error while restarting the camera engine.", e); new CameraUnavailableException("Error while restarting the camera engine.", e);
mCameraCallbacks.onError(cameraException); mCameraCallbacks.onError(cameraException);
} }
} }

@ -3,7 +3,11 @@ package com.otaliastudios.cameraview;
/** /**
* An object of this class describes an error that occurred during the normal runtime of the camera. * An object of this class describes an error that occurred during the normal runtime of the camera.
*/ */
public class CameraException extends RuntimeException { public abstract class CameraException extends RuntimeException {
CameraException(String message) {
super(message);
}
CameraException(String message, Throwable cause) { CameraException(String message, Throwable cause) {
super(message, cause); super(message, cause);

Loading…
Cancel
Save