Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

android - Video View not playing youtube video

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

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...