How to show Youtube movie

Hello everyone
I have ported my app to android using NDK and cocos2dx. Everything works fine except I need to show a Youtube movie (the trailer for my game). I dont care if this is done
from an embedded webview - or from a standalone browser.
I have been working with this all day and have not succeeded :frowning: . I am new with android dev, and therefore might have done this in a stupid way - please correct me.

Solution 1)
I have tried to add a webview, (with youtube url) to my OpenGl View, but this does never show. When replacing the webview with a TextView The text is shown correctly on top of my OpenGl view.
My implementation is seen below:

            String packageName = getApplication().getPackageName();
        super.setPackageName(packageName);

        RelativeLayout base = new RelativeLayout(this);
        FrameLayout frame = new FrameLayout(this);  

         mGLView = new Cocos2dxGLSurfaceView(this);
//       TextView testView = new TextView(this);
//       testView.setText("Hello, Android");

         WebView testView = new WebView(this);
         testView.loadUrl("http://www.google.dk/"); // THIS NEVER SHOW !!

         LinearLayout testLayout = new LinearLayout(this);

         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
         lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
         testLayout.addView(testView ,lp);

        frame.addView(mGLView);
        frame.addView(testLayout);
        base.addView(frame);
        setContentView(base);

Solution 2)
Then I have tried to launch a standalone browser by doing this:

    Uri uri = Uri.parse("http://www.youtube.com/watch?v=1FJHYqE0RDg");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);

This works fine if it is done before my OpenGl Scene is up and running. If I launch it when my Opengl Scene is running, my game crashes with the following information :

08-10 17:48:38.972: WARN/dalvikvm(11576): threadid=11: thread exiting with uncaught exception (group=0x40015560)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): FATAL EXCEPTION: GLThread 10
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): java.lang.NullPointerException
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at android.app.Activity.startActivityForResult(Activity.java:2827)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at android.app.Activity.startActivity(Activity.java:2933)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at org.cocos2dx.lib.PigsInTreesJavaCppComunication.pitTestJNI(PigsInTreesJavaCppComunication.java:54)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at org.cocos2dx.lib.Cocos2dxActivity.pitTestJNI(Cocos2dxActivity.java:174)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at org.cocos2dx.lib.Cocos2dxRenderer.nativeTouchesEnd(Native Method)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at org.cocos2dx.lib.Cocos2dxRenderer.handleActionUp(Cocos2dxRenderer.java:49)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at org.cocos2dx.lib.Cocos2dxGLSurfaceView$9.run(Cocos2dxGLSurfaceView.java:288)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1326)
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
08-10 17:48:39.019: WARN/ActivityManager(109): Force finishing activity dk.tactile.pigsInTrees/.pigsInTreesB
08-10 17:48:39.027: INFO/TAG(11576): onPause

I realy dont know what to do here :frowning:
Please help me.
Regards

Solution 2)
I think that you call web browser open from OpneGl thread. But you must do all UI operation from main thread.

For this you can use communication over Handler. Example of use is in Cocos2dxActivity.java - public static void showMessageBox(String title, String message).

Hi Milda - and thank you sooooo much!. you saved my day. :slight_smile: