skip to Main Content

I am looking to use camera2 for image and video capture. I found that for image capture I can use the method .setFlashMode(flash_type) but the video capture object does not have this.

CameraManager camManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    String cameraId = null; 
    try {
        cameraId = camManager.getCameraIdList()[0];
        camManager.setTorchMode(cameraId, true);   //Turn ON
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

I have tried using this method where I would turn on the flash before the video capture but was hit with an error which was due to the camera already being in use.

So, I am wondering, is this even possible in androidx yet?

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution over at the issue tracker for androidx.camera which seems to work.

    if (flash_type == ImageCapture.FLASH_MODE_ON)
        videoCapture.getCamera().getCameraControl().enableTorch(true);
    

    Any then do the opposite when stopping the video capture.


  2. Video capture in CameraX is not yet even an alpha-version public API, so it’s very possible it doesn’t yet support flash control.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search