Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 899ccfe

Browse files
committed
Enable autofocus
1 parent bf0a324 commit 899ccfe

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/main/java/net/majorkernelpanic/streaming/video/VideoStream.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,14 @@ public void onError(int error, Camera camera) {
590590
});
591591

592592
try {
593-
594-
// If the phone has a flash, we turn it on/off according to mFlashEnabled
595-
// setRecordingHint(true) is a very nice optimization if you plane to only use the Camera for recording
596593
Parameters parameters = mCamera.getParameters();
597-
if (parameters.getFlashMode()!=null) {
598-
parameters.setFlashMode(mFlashEnabled?Parameters.FLASH_MODE_TORCH:Parameters.FLASH_MODE_OFF);
594+
parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); // Enable autofocus
595+
parameters.setRecordingHint(true); // Lets the camera preview start faster.
596+
597+
if (parameters.getFlashMode()!=null) { // Set flash as requested, if it's present.
598+
parameters.setFlashMode(mFlashEnabled ? Parameters.FLASH_MODE_TORCH : Parameters.FLASH_MODE_OFF);
599599
}
600-
parameters.setRecordingHint(true);
600+
601601
mCamera.setParameters(parameters);
602602
mCamera.setDisplayOrientation(mOrientation);
603603

@@ -611,12 +611,10 @@ public void onError(int error, Camera camera) {
611611
} catch (IOException e) {
612612
throw new InvalidSurfaceException("Invalid surface !");
613613
}
614-
615614
} catch (RuntimeException e) {
616615
destroyCamera();
617616
throw e;
618617
}
619-
620618
}
621619
}
622620

@@ -638,7 +636,6 @@ protected synchronized void destroyCamera() {
638636
}
639637

640638
protected synchronized void updateCamera() throws RuntimeException {
641-
642639
// The camera is already correctly configured
643640
if (mUpdated) return;
644641

@@ -648,6 +645,8 @@ protected synchronized void updateCamera() throws RuntimeException {
648645
}
649646

650647
Parameters parameters = mCamera.getParameters();
648+
parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
649+
651650
mQuality = VideoQuality.determineClosestSupportedResolution(parameters, mQuality);
652651
int[] max = VideoQuality.determineMaximumSupportedFramerate(parameters);
653652

0 commit comments

Comments
 (0)