Log in or register to post comments

How to display a video instead of the teapot?

November 2, 2010 - 1:31am #1

When the tracker get the trackable in the frame ,i want to display a video instead of the teapot .
I start the project from the ImageTargets .I have hacked the ImageTargets.cpp , removed all the render code from renderFrame method and only return the trackable's name.It works well.

For playing a video ,I need add a SurfaceView Overlay on the GLSurfaceView.There is a SurfaceView Overlay example in the Android 2.2 APIDemo.I have studied the code and successfully played a video on the GLSurfaceView.

The following is our layout/main.xml file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <!-- Here is where we put the SurfaceView, in a frame so that we can
         stack other views on top of it. -->
    <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="0px"
            android:layout_weight="1">

        <android.opengl.GLSurfaceView android:id="@+id/mGLSurfaceview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />

        <LinearLayout android:id="@+id/hidecontainer"
                android:orientation="vertical"
                android:visibility="gone"
                android:background="@drawable/transparent_background"
                android:gravity="center"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
           
  			<SurfaceView
    			android:id="@+id/mSurface"
    			android:layout_width="176px " 
    			android:layout_height="144px"> 
  			</SurfaceView>
                    
        </LinearLayout>    
    </FrameLayout>

</LinearLayout>

I create the GLSurfaceView with the following code
mGlView = (QCARSampleGLView) findViewById(R.id.mGLSurfaceview);

if i setContentView(R.layout.main) on the onCreate method,it got the following errors

11-02 15:56:07.431: ERROR/AndroidRuntime(3949): FATAL EXCEPTION: main
11-02 15:56:07.431: ERROR/AndroidRuntime(3949): java.lang.NullPointerException
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:471)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.SurfaceView.updateWindow(SurfaceView.java:532)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.View.draw(View.java:6743)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewRoot.draw(ViewRoot.java:1407)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.os.Looper.loop(Looper.java:123)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at java.lang.reflect.Method.invokeNative(Native Method)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at java.lang.reflect.Method.invoke(Method.java:521)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-02 15:56:07.431: ERROR/AndroidRuntime(3949):     at dalvik.system.NativeStart.main(Native Method)

If i remove the setContentView code ,the program works well .Would you like give me some suggestion?Thank you!

Re: How to display a video instead of the teapot?

May 13, 2011 - 12:02pm #7

I need to do the same thing, how did you hacked the cpp file.
What i need to change, is possible to you to share with me some code?

Re: How to display a video instead of the teapot?

March 18, 2011 - 2:38am #6

I just did something like this:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(VIDEO_FILE), VIDEO_FILE_TYPE);
startActivity(intent);

This is not related to AR or QCAR SDK so you'd be best not to ask these types of questions here.

Re: How to display a video instead of the teapot?

March 17, 2011 - 11:11am #5

I want to display a video too, but i am having problems returning to the previous view. This is my code now, but it all goes black when the video finishes.

private  void playMovie(){
	// create the view (in this case it is already included in the layout resource)
	final VideoView videoview = new VideoView(getApplicationContext());

	Uri videouri = Uri.parse("android.resource://"+getClass().getPackage().getName()+"/raw/"+movie_file);
	videoview.setVideoURI(videouri);

	//hides videoview at the end of playback
	videoview.setOnCompletionListener(
			new MediaPlayer.OnCompletionListener() {
				public void onCompletion(MediaPlayer mp) {
					videoview.stopPlayback();
					addContentView(mGlView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
				}
			});

	setContentView(videoview, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
	videoview.requestFocus();

	// start the playback
	videoview.start();
}

Can anyone tell me how to make the mGlView come back with the camera running?
Thanks

Re: How to display a video instead of the teapot?

December 13, 2010 - 8:12am #4

The SDK does not expose this information in Java, but it is something you can do yourself. You will need to use the JNI (Java Native Interface) to pass information from native code to Java.

Please see the following thread for an example of passing tracking information from native to Java. The sample code given here will display a message from Java when a trackable first comes into view. You can adapt this code to perform other Java tasks when a target comes in view, and you can do something similar for when a target goes out of view.

http://ar.qualcomm.at/node/2000032

- Kim

Re: How to display a video instead of the teapot?

December 13, 2010 - 7:29am #3

And, how do you know when the tracker gets the trackable in frame in Java?

As I can see in ImageTarget sample, it is very easy to know that in C++.

And, how do you know when the trackable leaves frame?

Thank you.

Re: How to display a video instead of the teapot?

November 2, 2010 - 6:45am #2

It is important that the glView is initialized after the QCAR SDK has been initialized. Study the QCARSampleActivity class in the Shared project. You must call mGLView.init with the correct flags. Currently this is done in the initApplicationAR() method, which is called after QCAR has been successfully initialized.

Instead of adding the glView to the main.xml layout, it might be better to create a separate overlay view for your custom content and add it in a separate step. Let's name your overlay view myoverlay.xml. Now you could use the following code to add it on top of the glView:

// Now add the GL surface view. It is important
// that the OpenGL ES surface view gets added
// BEFORE the camera is started and video
// background is configured.
addContentView(mGlView, new LayoutParams(
                            LayoutParams.FILL_PARENT,
                            LayoutParams.FILL_PARENT));

View overlayView = View.inflate(this, R.layout.myoverlay, null);
addContentView(overlayView, new LayoutParams(
                            LayoutParams.FILL_PARENT,
                            LayoutParams.FILL_PARENT));

This code goes in the updateApplicationStatus method in the QCARSampleActivity class.

- Kim

Log in or register to post comments