我如何处理无法连接摄像头服务和Android上的多摄像头打开?

时间:2016-04-18 07:13:03

标签: android android-camera

我想要两个相机控制

首先我只尝试一个摄像头安装。 我看到相机预览

public class AndroidCamera extends Activity implements SurfaceHolder.Callback
{

    Camera camera;
    Camera camera2;
    SurfaceView surfaceView2;
    SurfaceView surfaceView;
    SurfaceHolder surfaceHolder;
    SurfaceHolder surfaceHolder2;

     Button buttonStartCameraPreview, buttonStopCameraPreview;

    boolean previewing = false;
    LinearLayout get_more;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


       buttonStartCameraPreview = (Button) findViewById(R.id.startcamerapreview);
       buttonStopCameraPreview = (Button) findViewById(R.id.stopcamerapreview);


        surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
        surfaceView2 = (SurfaceView) findViewById(R.id.surfaceview2);

        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        surfaceHolder2 = surfaceView2.getHolder();
        surfaceHolder2.addCallback(this);
        surfaceHolder2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);


        buttonStartCameraPreview.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (!previewing) {
                    camera = Camera.open(0);
                   if (camera != null){
                        try {
                            camera.setPreviewDisplay(surfaceHolder);
                            camera.startPreview();
                            previewing = true;
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }

            }
        });
        buttonStopCameraPreview.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (camera != null && previewing) {
                    camera.stopPreview();
                    camera.release();
                    camera = null;

                    previewing = false;
                }

            }
        });
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void surfaceCreated(SurfaceHolder holder)
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder)
    {
        // TODO Auto-generated method stub

    }

    } 

我想要两个相机控制

但我找不到多相机控制

我该如何编程?

我使用surfaceview 请给我建议

0 个答案:

没有答案