Swallow RuntimeExcpetions on autoFocus (#332)

pull/319/head^2
Mahdi 6 years ago committed by Mattia Iavarone
parent 73d73853d1
commit e0602c7ab6
  1. 7
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java

@ -823,6 +823,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
mCamera.setParameters(params);
mCameraCallbacks.dispatchOnFocusStart(gesture, p);
// TODO this is not guaranteed to be called... Fix.
try {
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
@ -832,6 +833,12 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay);
}
});
} catch (RuntimeException e) {
// Handling random auto-focus exception on some devices
// See https://github.com/natario1/CameraView/issues/181
LOG.e("startAutoFocus:", "Error calling autoFocus", e);
mCameraCallbacks.dispatchOnFocusEnd(gesture, false, p);
}
}
});
}

Loading…
Cancel
Save