Android: Camera2 switching between back and front camera -
i working on taking photo camera, , seems good, i'm using camera2basic sample, code offre camera added button switch between 2 cameras :
boolean facingcamera = true; // initialization
onclick() { facingcamera = !facingcamera; closecamera(); opencamera(mtextureview.getwidth(), mtextureview.getheight()); }
and changed method setupcameraoutputs code :
if (facing != null && facing == cameracharacteristics.lens_facing_front ) { continue; }
to
if (facing != null && facing == cameracharacteristics.lens_facing_front && !facingcamera || facing != null && facing == cameracharacteristics.lens_facing_back && facingcamera ) { continue; }
this work fine nexus 4 lg-d802 not working fine ( onconfigurefailed called each time try change camera )
how fix work fine on devices?
did check if cameramanager giving 2 available cameras? use cameramanager.getcameraidlist()
check it. remember right preview sizes each camera using cameracharacteristics:
streamconfigurationmap rearmap = rearcameracharacteristics.get( cameracharacteristics.scaler_stream_configuration_map); streamconfigurationmap frontmap = frontcameracharacteristics.get( cameracharacteristics.scaler_stream_configuration_map);
after use 1 of values initialize preview, if using same value front , camera maybe having problems cause front camera don't support resolution size.
Comments
Post a Comment