I am having problems with my touch-to-focus implementation using Camera2 APIs. Here is my code:
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
if (isMeteringAreaAESupported()) {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS,
new MeteringRectangle[]{focusArea});
}
if (isMeteringAreaAFSupported()) {
mPreviewRequestBuilder
.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{focusArea});
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_AUTO);
}
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_START);
try {
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null,
mBackgroundHandler);
mManualFocusEngaged = true;
} catch (CameraAccessException e) {
}
The problem I see is the strange behavior with the flash on some devices, when the above code is called several times in a short period of time (for example, the user touches the screen too quickly before the focus is set). For example, in S5, it looks like all requests are queued, and if the user touches several times, they are executed one after another for a while. On my Nexus 5, the flash will not flash from the request to the request, but will be constantly on until the last request is completed.
, , Google . Google, , .
mCaptureSession.abortCaptures(); , . mCaptureSession.stopRepeating(); .