Skip to content

Commit

Permalink
Handle getParameters() failure in onPreviewFrame().
Browse files Browse the repository at this point in the history
  • Loading branch information
rkistner committed Mar 20, 2017
1 parent e3aed41 commit 2cf4b60
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ public void onPreviewFrame(byte[] data, Camera camera) {
Size cameraResolution = resolution;
PreviewCallback callback = this.callback;
if (cameraResolution != null && callback != null) {
int format = camera.getParameters().getPreviewFormat();
try {
int format = camera.getParameters().getPreviewFormat();
SourceData source = new SourceData(data, cameraResolution.width, cameraResolution.height, format, getCameraRotation());
callback.onPreview(source);
} catch (IllegalArgumentException e) {
// Image data does not match the resolution
} catch (RuntimeException e) {
// Could be:
// java.lang.RuntimeException: getParameters failed (empty parameters)
// IllegalArgumentException: Image data does not match the resolution
Log.e(TAG, "Camera preview failed", e);
callback.onPreviewError(e);
}
Expand Down

0 comments on commit 2cf4b60

Please sign in to comment.