How to show Youtube movie

How to show Youtube movie
0.0 0


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();

        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(""); // THIS NEVER SHOW !!

         LinearLayout testLayout = new LinearLayout(this);

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


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

    Uri uri = Uri.parse("");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);

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
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at org.cocos2dx.lib.PigsInTreesJavaCppComunication.pitTestJNI(
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at org.cocos2dx.lib.Cocos2dxActivity.pitTestJNI(
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(
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at org.cocos2dx.lib.Cocos2dxGLSurfaceView$
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at android.opengl.GLSurfaceView$GLThread.guardedRun(
08-10 17:48:38.996: ERROR/AndroidRuntime(11576): at android.opengl.GLSurfaceView$
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.


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 - public static void showMessageBox(String title, String message).


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