Log in or register to post comments

playing video over camera view

October 9, 2012 - 7:23pm #1

My requiremenet is to play a video when a trackable is found.


I was following the samples and in my app , in GuiManager, i inflate a layout with a linear layout.

Now within this linear layout i want to play a video when a matching target is found.

SO the video will be actually over the camera view , video playing in the centre, and behind that camera view visible.


I tried using webview, mediaplayer and videoview but no success.

Is there any link / demo that can help me to proceed.

Please share.


thanks a lo

playing video over camera view

April 19, 2013 - 7:33am #11

What is the Android version this solution works for? I tried it on Android 2.3.x without success. It only works on Android 3.2 and greater...can you confirm it?

playing video over camera view

October 14, 2012 - 2:35pm #10

Sounds great! Very interesting use case by the way, thanks for sharing this.


playing video over camera view

October 14, 2012 - 2:15am #9

Thank you very much. It worked. I just had to call setZOrderMediaOverlay for the surface view in the existing layout that i added.

It works perfect.

Thanks a lot for this support .

playing video over camera view

October 10, 2012 - 6:43am #8

Hi again, I further investigated your issue and it seems the problem comes from the fact that VideoView is a SurfaceView, and the OpenGL view of Vuforia is a SurfaceView as well;

 and SurfaceViews are special types of Views which are handled by Android in a very special way; SurfaceViews are z-ordered and somehow rendered below the window they belong to.

In practice, combining multiple SurfaceViews together is not that obvious as it would be for regular views;

so, what I can suggest is to try and add the VideoView directly on top of the GL view of Vuforia (i.e. without embedding the VideoView in a Layout), directly using addContentView(  ) ,  and then call the method setZOrderMediaOverlay( true ), in practice something like:

addContentView( mGLView );


addContentView ( mVideoView );

mVideoView.setZOrderMediaOverlay ( true );

This should somehow enforce the VideoView to stay "on top" of any other surfaceView in the same window (namely the OpenGL view with the camera video feed);

You can find more details on the SurfaceView API at this link:


I hope this will help you solve the issue.


playing video over camera view

October 10, 2012 - 6:32am #7

Thanks you very much.

I will keep digging and share it if i figure out the issue.

Thanks for all the responses

playing video over camera view

October 10, 2012 - 6:08am #6

Indeed the sample starts a new activity to embed the video, which is a bit different from what you want;

what I'm saying is not to use the same code (i.e. you can stick to your approach of using adding a view on top, without starting a new activity),

but rather you could just have a look at the sample code, for instance to see if you can find some hints on how to setup VideoView and MediaPlayer, maybe checking some differences between your code and the code in the sample......hoping you can find something useful in it. I cannot go into all of your application-specific details, but I believe the sample code could really help you dig in the right direction.

On the other hand, if you find out something interesting feel free to share it ...



playing video over camera view

October 10, 2012 - 5:50am #5

Thanks a lot for the explanations. Its really helpful.

I had browsed through the videoplayback example. In that the fullscreen is entirely a new activity . SO here it is setting a new view content and playing video .It is not with camera at the background instead it is a new activity. 

My requirement was to play video over the camera view . Like showing a button or textview .

Please let me know your comments

Thanks again for your responses. Its really helpful.



playing video over camera view

October 10, 2012 - 5:30am #4

Hi, in Android every surface has an associated SurfaceHolder; you can roughly think of it as a sort of wrapper or manager for a given surface; i.e. instead of handling the surface directly, Android basically lets you play with a "surface" via its "holder".

so, when you call "mediaPlayer.setDisplay ( holder )",  you are basically telling the media player what is the target surface on which to display the video, but instead of saying "this is the surface I want to use", you will say "this is the surfaceHolder I want to use";

so we basically use surfaceHolders instead of surfaces, but there's nothing really complicated behind that.

Also, a SurfaceFolder allows you to specify callbacks that can be used to handle events related to the surface creation, surface change or surface destroyed.

Apart from the above, there could be many reasons why your view is not displayed properly;

I would then recommend that you take a look at the Vuforia Video-Playback sample that you can find here:


In this sample, you can take a look at the class FullscreenPlayback, which also makes use of a VideoView, but in this case arranged inside a FrameLayout (and centered with the gravity layout parameter);

you could then adapt the code to make it appear smaller than the fullscreen size (check the code in onVideoSizeChanged() method).


This should hopefully help you, and in that sample you can implicitly find a lot of best practices on how to play videos with media player and videoview.





playing video over camera view

October 10, 2012 - 4:54am #3

Thank you very much for the answer. I was also thinking in similar lines but i am missing something.


public GUIManager(Context context,Activity activity)



        overlayView = View.inflate(context, R.layout.interface_overlay, null);


            surface= (SurfaceView)overlayView.findViewById(R.id.surface);




 mMediaPlayer = new MediaPlayer();








holder = surface.getHolder();




i think the catch is the last line. ie display is set to holder, which is the holder for surface view . Now what is that ?? !

What i see is using mediaplayer the vide is played but not really visible. Its going somewhere background. If i press back i can just get a glimpse of it before the activity is closed.

I had tried setting text view and it is working fine. The surface is the surface view defined in my layout. 


Can you please help me to understand what is going wrong and how to fix it.



playing video over camera view

October 10, 2012 - 2:45am #2

Hi, geenrally speaking it should be easy to show a layout (view) on top of another; one way of doing that programmatically is to use addContentView() so to add the "top" layout (i.e. the one with the video) on top of the existing "background" layout (in this case your AR view);

If you have problems with the videoview, I would perhaps suggest to first try to add a simple layout with some simple widget (e.g. a Button, or a TextView) instead of the videoview (so basically place a button on top of the AR view), and then try to replace your button with an actual VideoView (which is just a sort of view wrapper for MediaPlayer);

also, when doing that, I would use a RelativeLayout as layout to contain your VideoView, and use some of parameters of such layout to center the VideoView horizontally and vertically; another thing to consider is to add some "padding" (e.g. leftPadding, rightPadding, etc.), which is also supported by RelativeLayout.


Log in or register to post comments