开发者

Android dev : How to show Youtube movie?

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

     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 1开发者_Go百科7: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: onPause

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


I couldnt look deeply to your code but here is code sample that opening youtube video from gallery of video thumbnails that I am using in one of my applications, if youtube application presents with browser it ask the user to select default one.

videoGalery.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub

                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(//your url goes here));
             }
           });

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜