我已经实现了一个使用camera2 API录制视频的自定义相机。可以选择将闪光设置为"开","关"和"自动"。 将闪光灯设置为"自动"不起作用,而其他选项工作正常。
以下是代码:
private void updateFlash() {
Log.e(TAG, "Flash = " + currentFlash);
switch (currentFlash) {
case Constants.FLASH_OFF:
previewRequestBuilder.set(CaptureRequest.FLASH_MODE,
CaptureRequest.FLASH_MODE_OFF);
break;
case Constants.FLASH_ON:
previewRequestBuilder.set(CaptureRequest.FLASH_MODE,
CaptureRequest.FLASH_MODE_TORCH);
break;
case Constants.FLASH_TORCH:
previewRequestBuilder.set(CaptureRequest.FLASH_MODE,
CaptureRequest.FLASH_MODE_TORCH);
break;
case Constants.FLASH_AUTO:
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
break;
}
cameraCaptureSession.setRepeatingRequest(previewRequestBuilder.build(),
null, null);
}
我已经google了很多,并尝试了几乎所有的自动闪存的stackoverflow答案,但都没有。
请帮助。我不明白这是什么问题。
答案 0 :(得分:0)
我欺骗了!我写了一个CaptureCallback
,在onCaptureCompleted
回调中,我得到了AE_STATE
,如果AE_STATE
等于CONTROL_AE_STATE_FLASH_REQUIRED
,那么我将手动打开闪光灯。该解决方案不适用于某些设备,例如Samsung J7或Samsung A5。在AE_STATE
返回null的设备上,此解决方案无效。半面包总比没有面包好。 :)
private CameraCaptureSession.CaptureCallback captureCallback
= new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
if (previewFlashMode == FLASH_AUTO) {
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState != null) {
if (currentPreviewFlashMode != FLASH_ON && aeState == CaptureResult.CONTROL_AE_STATE_FLASH_REQUIRED) {
setFlashMode(captureRequestBuilder, FLASH_ON);
setRepeatingRequestAfterSetFlash();
}
}
}
}
};
您应将回调添加到setRepeatingRequest
。