Monday, 9 August 2021

How to automatically turn on flashlight for video recording when the scene is dark?

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

What I'm trying to achieve is to automatically turn on flashlight (torch mode) as soon as the video recording starts.

However I couldn't find a way to do so. On Camera2 API we can use FLASH_MODE_AUTO which will use the flashlight when capturing photo when the scene is dark, but that doesn't work for video recording. There's this FLASH_MODE_TORCH which I could use to turn on the flashlight just like I wanted, but there isn't a FLASH_MODE_TORCH_AUTO to automatically do so when the scene is dark..

There were some answers that uses Ambient light sensor (Sensor.TYPE_LIGHT) of the device to determine whether we are in a dark scene, however that uses the front ambient light sensor instead of the camera itself I think. This is not ideal as the ambient light can be low but the rear camera is able to adjust exposure level to achieve good enough image quality without using flash. So ideally if the camera says 'flash is required' then only the app activates FLASH_MODE_TORCH.

Since the app shows a preview the device already know whether flash is needed before the button press, is there a way to determine whether flash is required during preview?



from How to automatically turn on flashlight for video recording when the scene is dark?

No comments:

Post a Comment