Switch between camera in android for Camera2Api -


i using snipped of code switch between cameras old camera api

imagebutton useothercamera = (imagebutton) findviewbyid(r.id.useothercamera); //if phone has 1 camera, hide "switch camera" button if(camera.getnumberofcameras() == 1){     useothercamera.setvisibility(view.invisible); } else {     useothercamera.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view v) {     if (inpreview) {         camera.stoppreview();     }     //nb: if don't release current camera before switching, app crash     camera.release();      //swap id of camera used     if(currentcameraid == camera.camerainfo.camera_facing_back){         currentcameraid = camera.camerainfo.camera_facing_front;     }     else {         currentcameraid = camera.camerainfo.camera_facing_back;     }     camera = camera.open(currentcameraid);     //code snippet method somewhere on android developers, forget     setcameradisplayorientation(cameraactivity.this, currentcameraid, camera);     try {         //this step critical or preview on new camera no know render         camera.setpreviewdisplay(previewholder);     } catch (ioexception e) {         e.printstacktrace();     }     camera.startpreview(); } 

how same camera2api ?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -