android - CWAC CAMERA-switching Front-Back camera not working -
i have integrated [cwac-camera][1].i trying switch between , front camera clicking on button using below code not working.i can see default camera.where going wrong?
private boolean isbackcam=true; f = new camerafragment(); builder=new simplecamerahost.builder(new democamerahost(getapplicationcontext())); f.sethost(builder.usefullbleedpreview(true).build()); handleswitchcamera=(imagebutton)findviewbyid(r.id.handleswitchcamera); handleswitchcamera.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if(isbackcam) { isbackcam=false; builder.usefrontfacingcamera(true); } else { isbackcam=true; builder.usefrontfacingcamera(false); } } });
updated according commonsware answer-
f = new camerafragment(); getfragmentmanager().begintransaction() .add(r.id.preview_view, f, tag_camera_fragment) .commit(); f2 = new camerafragment(); builder=new simplecamerahost.builder(new democamerahost(getapplicationcontext())); builder2=new simplecamerahost.builder(new democamerahost(getapplicationcontext())); builder.usefrontfacingcamera(false); builder2.usefrontfacingcamera(true); f.sethost(builder.usefullbleedpreview(true).build()); f2.sethost(builder2.usefullbleedpreview(true).build()); handleswitchcamera.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if(isbackcam) { log.e("bhuvnesh","backcam"); isbackcam=false; getfragmentmanager().begintransaction() .replace(r.id.preview_view, f2, tag_camera_fragment) .commit(); } else { log.e("bhuvnesh","frontcam"); isbackcam=true; getfragmentmanager().begintransaction() .replace(r.id.preview_view, f, tag_camera_fragment) .commit(); } } }); [1]: https://github.com/commonsguy/cwac-camera
you need call sethost()
after configuring builder
. cannot change builder
later on , expect change.
note sethost()
designed called once per fragment. if want switch between cameras, need switch fragments (one per camera), demo app does.
Comments
Post a Comment