Skip to content

Commit

Permalink
Added overload: open(cameraId)
Browse files Browse the repository at this point in the history
  • Loading branch information
slepmog committed May 1, 2014
1 parent 07bdeb9 commit 5b957c8
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ public final class OpenCameraInterface {
private OpenCameraInterface() {
}


/**
* Opens the requested camera with {@link Camera#open(int)}, if one exists.
*
* @param cameraId camera ID of the camera to use
* @return handle to {@link Camera} that was opened
*/
public static Camera open(int cameraId) {
if (cameraId < 0) {
Log.w(TAG, "Requested invalid camera ID: " + cameraId);
return null;
}

int numCameras = Camera.getNumberOfCameras();

if (numCameras == 0) {
Log.w(TAG, "No cameras!");
return null;
}

Camera camera;
if (cameraId < numCameras) {
Log.i(TAG, "Opening camera #" + cameraId);
camera = Camera.open(cameraId);
} else {
Log.w(TAG, "Requested camera does not exist: " + cameraId);
camera = null;
}

return camera;
}


/**
* Opens a rear-facing camera with {@link Camera#open(int)}, if one exists, or opens camera 0.
*
Expand Down

0 comments on commit 5b957c8

Please sign in to comment.