Java Code Examples for android.hardware.camera2.CameraAccessException#getMessage()

The following examples show how to use android.hardware.camera2.CameraAccessException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomVideoCapturerCamera2.java    From opentok-android-sdk-samples with MIT License 6 votes vote down vote up
public CustomVideoCapturerCamera2(Context ctx,
                            Publisher.CameraCaptureResolution resolution,
                            Publisher.CameraCaptureFrameRate fps) {
    cameraManager = (CameraManager) ctx.getSystemService(Context.CAMERA_SERVICE);
    display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    camera = null;
    cameraState = CameraState.CLOSED;
    reentrantLock = new ReentrantLock();
    condition = reentrantLock.newCondition();
    frameDimensions = resolutionTable.get(resolution.ordinal());
    desiredFps = frameRateTable.get(fps.ordinal());
    runtimeExceptionList = new ArrayList<RuntimeException>();
    isPaused = false;
    try {
        String camId = selectCamera(PREFERRED_FACING_CAMERA);
        /* if default camera facing direction is not found, use first camera */
        if (null == camId && (0 < cameraManager.getCameraIdList().length)) {
            camId = cameraManager.getCameraIdList()[0];
        }
        cameraIndex = findCameraIndex(camId);
    } catch (CameraAccessException e) {
        throw new Camera2Exception(e.getMessage());
    }
}
 
Example 2
Source File: CustomVideoCapturerCamera2.java    From opentok-android-sdk-samples with MIT License 5 votes vote down vote up
@Override
public synchronized void cycleCamera() {
    try {
        String[] camLst = cameraManager.getCameraIdList();
        swapCamera((cameraIndex + 1) % camLst.length);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new Camera2Exception(e.getMessage());
    }
}
 
Example 3
Source File: CustomVideoCapturerCamera2.java    From opentok-android-sdk-samples with MIT License 5 votes vote down vote up
@SuppressLint("all")
private void initCamera() {
    Log.d(LOG_TAG,"initCamera()");
    try {
        cameraState = CameraState.SETUP;
        // find desired camera & camera ouput size
        String[] cameraIdList = cameraManager.getCameraIdList();
        String camId = cameraIdList[cameraIndex];
        camFps = selectCameraFpsRange(camId, desiredFps);
        Size preferredSize = selectPreferredSize(
                camId,
                frameDimensions.getWidth(),
                frameDimensions.getHeight(),
                PIXEL_FORMAT
        );
        cameraFrame = ImageReader.newInstance(
                preferredSize.getWidth(),
                preferredSize.getHeight(),
                PIXEL_FORMAT,
                3
        );
        cameraFrame.setOnImageAvailableListener(frameObserver, cameraThreadHandler);
        characteristics = new CameraInfoCache(cameraManager.getCameraCharacteristics(camId));
        cameraManager.openCamera(camId, cameraObserver, cameraThreadHandler);
    } catch (CameraAccessException exp) {
        throw new Camera2Exception(exp.getMessage());
    }
}
 
Example 4
Source File: CustomVideoCapturerCamera2.java    From opentok-android-sdk-samples with MIT License 4 votes vote down vote up
private int doStartCapture() {
    Log.d(LOG_TAG,"doStartCapture enter");
    try {
        // create camera preview request
        if (isFrontCamera()) {
            captureRequestBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            captureRequestBuilder.addTarget(cameraFrame.getSurface());
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, camFps);
            captureRequestBuilder.set(
                    CaptureRequest.CONTROL_MODE,
                    CaptureRequest.CONTROL_MODE_USE_SCENE_MODE
            );
            captureRequestBuilder.set(
                    CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
            );
            captureRequestBuilder.set(
                    CaptureRequest.CONTROL_SCENE_MODE,
                    CaptureRequest.CONTROL_SCENE_MODE_FACE_PRIORITY
            );
            camera.createCaptureSession(
                    Arrays.asList(cameraFrame.getSurface()),
                    captureSessionObserver,
                    cameraThreadHandler
            );
        } else {
            captureRequestBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
            captureRequestBuilder.addTarget(cameraFrame.getSurface());
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, camFps);
            captureRequestBuilder.set(
                    CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
            );
            camera.createCaptureSession(
                    Arrays.asList(cameraFrame.getSurface()),
                    captureSessionObserver,
                    cameraThreadHandler
            );
        }
    } catch (CameraAccessException e) {
        throw new Camera2Exception(e.getMessage());
    }
    Log.d(LOG_TAG,"doStartCapture exit");
    return 0;
}