Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: record video with "continuous" auto-focus

I work on video recording; everything works except for requesting continuous focus. This is what I do (tried both in surfaceCreated and surfaceChanged with no success):

camera = Camera.open();
camera.setPreviewDisplay(holder);

Parameters parameters = camera.getParameters();

then I do either

parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);

or

parameters.set("focus-mode", "continuous-video");

both should do the same thing; then I set parameters with

camera.setParameters(parameters);

This last line always crashes! So do I miss something?

By the way, I test on rather new devices like Desire HD, Galaxy S, Galaxy Tab 7 and 10.1, which must have support for continuous auto-focus; at least their built-in camera apps support it.

like image 868
myself Avatar asked Oct 13 '11 12:10

myself


1 Answers

You should check if Continuous Auto Focus is supported by the device. This is something that works for me, please give it a try.

boolean startContinuousAutoFocus() {

    Camera.Parameters params = mCamera.getParameters();

    List<String> focusModes = params.getSupportedFocusModes();

    String CAF_PICTURE = Parameters.FOCUS_MODE_CONTINUOUS_PICTURE, 
           CAF_VIDEO = Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, 
           supportedMode = focusModes
                   .contains(CAF_PICTURE) ? CAF_PICTURE : focusModes
                   .contains(CAF_VIDEO) ? CAF_VIDEO : "";

    if (!supportedMode.equals("")) {

        params.setFocusMode(supportedMode);
        mCamera.setParameters(params);
        return true;
    }

    return false;
}
like image 52
user1527786 Avatar answered Oct 13 '22 04:10

user1527786