我希望能够在启动应用程序时使用此代码从后到前(或从前到后)切换相机,第一个开关可以工作,但其他开关不能:
public void changeCameraOnFly(View v)
{
if (isPreview) {camera.stopPreview();}
camera.release();
System.out.println("Camera ID before : " + String.valueOf(cameraID));
if(cameraID == 0) {cameraID++;}
if(cameraID == 1) {cameraID--;}
System.out.println("Camera ID after: " + String.valueOf(cameraID));
camera = Camera.open(cameraID);
try {
//this step is critical or preview on new camera will no know where to render to
camera.setPreviewDisplay(surfaceCamera.getHolder());
}
catch (IOException e) { e.printStackTrace(); }
camera.startPreview();
}
调试日志:
06-17 18:27:43.594: I/System.out(10551): Camera ID before : 1
06-17 18:27:43.594: I/System.out(10551): Camera ID after: 0
06-17 18:27:46.074: I/System.out(10551): Camera ID before : 0
06-17 18:27:46.074: I/System.out(10551): Camera ID after: 0