Video View not playing youtube video

烂漫一生 提交于 2019-11-26 21:41:16

问题


I am trying to play a youtube video in a Video View.

I have laid out the xml like this:

<VideoView 
            android:id="@+id/VideoView"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent" 
            />

and the code is like this:

setContentView(R.layout.webview);
        VideoView vv = (VideoView) findViewById(R.id.VideoView);                        
        MediaController mc=new MediaController(this);
        mc.setEnabled(true);
        mc.show(0);
        vv.setMediaController(mc); 
        vv.setVideoURI(Uri.parse("http://www.youtube.com/watch?v=XS998HaGk9M"));
        vv.requestFocus();
        vv.showContextMenu();
        vv.start();  

I have added the permission within the manifest. When I load the application a dialog appears stating the video cannot be played.

I would appreciate any advice on this. Thanks


回答1:


While not an explicit answer I believe you need to launch an intent with a YouTube URL and let the OS handle it. That is, I don't think you can embed YouTube videos directly into your activities though I would love to be proven wrong.




回答2:


You specified wrong URI for the video. http://www.youtube.com/watch?v=XS998HaGk9M is a web page, but not directly a video stream

Here is correct URI example:

rtsp://v6.cache4.c.youtube.com/CigLENy73wIaHwmh5W2TKCuN2RMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp

Also, this address can be obtained from YouTube API. For example, from here: http://gdata.youtube.com/feeds/api/users/phonedog/uploads




回答3:


Android webview and videoviews do not support play back of youtube videos in my experience.



来源:https://stackoverflow.com/questions/5162088/video-view-not-playing-youtube-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!