Having two SurfaceViews!?

All your problems with Audio, Video and Images.

Having two SurfaceViews!?

Postby himym » Sat Oct 24, 2009 1:29 pm

Hi everybody,
I am relatively new to this whole android thing, so any kind of help is very much appreciated.
My problem is: I have a camera-surfaceview, which brings me my live camerastream on the display. Now i like to add some dynamic content on top of it. I was thinking about having another SurfaceView and show the content in a Canvas. Unfortunatelly the one SurfaceView always overrides the other one, meaning I only can see the first one which is added to my View.
Is there any possibility two show both Views at the same time, or setting the second SurfaceView to be transparent?

Thanks a lot in advance
Regards
himym
Developer
Developer
 
Posts: 33
Joined: Sun Oct 18, 2009 9:50 am

Top

Postby chimaera » Wed Nov 04, 2009 1:05 am

Hi,

The simplest way is to use the same SurfaceView.

In your rendering thread, you'll have to lock the canvas:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Canvas canvas = holder.lockCanvas();
  2.  
  3. ...
  4.  
  5. holder.unlockCanvasAndPost(canvas);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


The Camera will do the same when you do:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mCamera.setPreviewDisplay(holder);
  2.  
  3. mCamera.startPreview();
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


So you won't have locking issues.

A another solution is to use a RelativeLayout:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. main_layout = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.main, null, false);
  2.  
  3.      
  4.  
  5.         main_layout.addView(cameraview, 0);
  6.  
  7.         main_layout.addView(overlayview, 1);
  8.  
  9.        
  10.  
  11.         setContentView(main_layout);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
chimaera
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Jun 19, 2009 1:42 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 21 guests