3

I want to create an android app with a surfaceview that fills the left part of the screen and with another second surfaceview that fills the right part of the screen.

In both surfaceviews should be a preview of the camera. So that there are two exactly similar camera pictures side by side.

I tried it like this (i will remove the button and onclick part etc when i solved my surfaceview problem):

 getWindow().setFormat(PixelFormat.UNKNOWN);
   surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
   surfaceHolder = surfaceView.getHolder();
   surfaceHolder.addCallback(this);
   surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

   surfaceView2 = (SurfaceView)findViewById(R.id.SurfaceView02);
   surfaceHolder2 = surfaceView2.getHolder();
   surfaceHolder2.addCallback(this);
   surfaceHolder2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

  buttonStartCameraPreview.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(!previewing){

 camera = Camera.open();

 if (camera != null){

   try {

       camera.setPreviewDisplay(surfaceHolder);
       camera.setPreviewDisplay(surfaceHolder2);

} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

   camera.startPreview();
   previewing = true;


 }
} 
}});

But obviously it just displays the preview in the "last" surfaceHolder (here: surfaceHolder2). I hope you can help me :)

  • 1
    Can you show the XML layout for the activity? You may want to use a TextureView here; see e.g. "Double decode" in https://github.com/google/grafika . – fadden Feb 10 '14 at 17:59
  • 1
    Okay the reason why this is not working is simply that you can have only one previewdisplay. So while calling the setPreviewDisplay method the second time you overwrite the first surfaceHolder. – Shorty123 Aug 27 '14 at 11:03
  • Where you ever able to solve this? – luckasfrigo Apr 12 '16 at 05:18

0 Answers0