How to add autofocus feature to camera
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...........");
}
};
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);
}
Hi @dvidz ,
I tried this but it didn't work :( Can you suggest some other solution
Hi Dvidz, Even I tried your code, but It din't help. Is there any other way?
Try to change :
Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO
by
Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
Thanks a lot @dvidz : Our problem is solved :-)
Thanks a ton dvidz. Even my problem is solved.
@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