Using Camera2 I want to turn on flashlight when Android Recording

Viewed 96

My app shows a preview and video recording starts with a button press.

What I'm trying to achieve is when I press the button, it'll turn on flashlight after 2 second and it's still recording.

However I couldn't find a way to do so. On Camera2 API I can use FLASH_MODE_AUTO to turn on the flashlight before recording video, but that doesn't work when video recording.

I also tried to build another button for control flashlight, but if I don't build preview before flashlight, it won't work, and if I build it, it will stock the app, I'm guessing cause I call the preview twice.

If anyone have same question with mine, we can discuss.

1 Answers

To manually control the flashlight with camera2, you need to set CONTROL_AE_MODE to ON to disable automatic flash control, and set FLASH_MODE to OFF to start with the flash off, in your initial repeating request.

Once you want to turn the flashlight on while you're recording, set FLASH_MODE to TORCH.

Related