我使用googlesample制作了一款相机Android应用。我需要相机将重新聚焦于视频录制的开始以及每次用户在录制视频时按下对焦按钮。我在哪里可以找到如何实现它的示例?
这是我的Camera2VideoFragment及其parent类
答案 0 :(得分:0)
您需要添加捕捉回叫以将焦点控制添加到您的相机会话。
private boolean firstCaptureDone = false;
private CameraCaptureSession.CaptureCallback captureCallback = null;
captureCallback = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
boolean cameraFocussed = false;
private void process(CaptureResult result) {
int afState = result.get(CaptureResult.CONTROL_AF_STATE);
if (CaptureResult.CONTROL_AF_TRIGGER_START == afState) {
if (cameraFocussed) {
if (firstCaptureDone) {
firstCaptureDone = true;
Log.d(TAG, "firstCapture Done with focus");
}
}
}
if (CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED == afState) {
cameraFocussed = true;
} else {
cameraFocussed = false;
}
}
};
mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), captureCallback, mBackgroundHandler);