Update. To make it really instant the code should be like this:
//final AutoFocusFeature autoFocusFeature = cameraFeatures.getAutoFocus();
//final boolean isAutoFocusSupported = autoFocusFeature.checkIsSupported();
//if (isAutoFocusSupported && autoFocusFeature.getValue() == FocusMode.auto) {
// runPictureAutoFocus();
//} else {
// runPrecaptureSequence();
//}
takePictureAfterPrecapture();
In my case (Google Pixel 3, Google Pixel 7) it was because despite camera is already focused in preview mode, when you take a picture it will focus again and it usually takes 1-several seconds to complete, which makes plugin useless in production. (BTW, I tried to fix this from the other side, using image stream, which worked perfectly fast, but in that mode image quality is much lower, it seems to be another issue.)
I've found a workaround for this issue while it is still exists in camera 0.10.5+2.
I've modified the takePicture
method inside the Camera.java file. Just commented out 3 lines at the end:
//if (isAutoFocusSupported && autoFocusFeature.getValue() == FocusMode.auto) {
// runPictureAutoFocus();
//} else {
runPrecaptureSequence();
//}
Now autofocusing works during preview, and then, when you call takePicture
, in most of the cases it will return instantly. Not always, but it is much, much better than it was before. Now it is usable.
(To do it you need to copy this package locally, modify the file, and then add this section to your pubspec.yaml:
dependency_overrides:
camera_android:
path: ../camera_android
Don't forget to check path to the local copy.)