libstreaming icon indicating copy to clipboard operation
libstreaming copied to clipboard

How to add autofocus feature to camera

Open ghost opened this issue 10 years ago • 7 comments

Hi All,

I am trying to implement the autofocus feature in my livestreaming project. I initially made a sample native Android project as mentioned in this link [http://android-er.blogspot.in/2011/01/start-camera-auto-focusing-autofocus.html ]

However, when I am trying to do the same using libstreaming, I am not getting the desired result.

Here is the code in my live streaming project that uses libstreaming

            {
                   /*auto focus feature*/
    RelativeLayout layoutBackground = (RelativeLayout)findViewById(R.id.surface_layout);
    layoutBackground.setOnClickListener(new RelativeLayout.OnClickListener(){
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            setCameraFocus(myAutoFocusCallback);
        }
    });
      } //onCreate ends

          public static void setCameraFocus(AutoFocusCallback autoFocus){
    if (VideoStream.mCamera.getParameters().getFocusMode().equals(VideoStream.mCamera.getParameters().FOCUS_MODE_AUTO) ||
            VideoStream.mCamera.getParameters().getFocusMode().equals(VideoStream.mCamera.getParameters().FOCUS_MODE_MACRO)){
        VideoStream.mCamera.getParameters().setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        VideoStream.mCamera.autoFocus(autoFocus);

    }
}

private AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback(){
    public void onAutoFocus(boolean autoFocusSuccess, Camera arg1) {
            //I get the log message every time but the auto focus isn't happening on screen
                Log.i("App", "Auto focus called success...........");

    }
};

ghost avatar Dec 25 '15 07:12 ghost

Hi,

perhaps it will help

add this on VideoStream.java around line 600 & 660

if (parameters.getSupportedFocusModes().contains(
            Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }

dvidz avatar Dec 26 '15 09:12 dvidz

Hi @dvidz ,

I tried this but it didn't work :( Can you suggest some other solution

ghost avatar Dec 26 '15 14:12 ghost

Hi Dvidz, Even I tried your code, but It din't help. Is there any other way?

ghost avatar Dec 27 '15 06:12 ghost

Try to change :

Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO

by

Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE

dvidz avatar Dec 27 '15 22:12 dvidz

Thanks a lot @dvidz : Our problem is solved :-)

ghost avatar Dec 31 '15 15:12 ghost

Thanks a ton dvidz. Even my problem is solved.

ghost avatar Jan 03 '16 10:01 ghost

@karanbalkar @dvidz @ram10609601 Hi all, Can you please see my post here and help me? It is directly related to FOCUS MODE that seems to be resolved by you. Thank you

HjoshM avatar Jun 16 '17 14:06 HjoshM