视频视图不播放 YouTube 视频
我正在尝试在视频视图中播放 YouTube 视频。
我已经将 xml 布局如下:
<VideoView
android:id="@+id/VideoView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
代码如下:
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您为视频指定了错误的 URI。
http://www.youtube.com/watch?v=XS998HaGk9M 是一个网页,但不是直接的视频流
这是正确的 URI 示例:
另外,该地址可以从 YouTube API 获取。
例如,从此处:http://gdata.youtube.com/feeds/api/users/phonedog/上传
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:
Also, this address can be obtained from YouTube API.
For example, from here: http://gdata.youtube.com/feeds/api/users/phonedog/uploads
虽然不是明确的答案,但我相信您需要使用 YouTube URL 启动意图并让操作系统处理它。也就是说,我认为您不能将 YouTube 视频直接嵌入到您的活动中,尽管我希望被证明是错误的。
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.
根据我的经验,Android webview 和 videoview 不支持播放 YouTube 视频。
Android webview and videoviews do not support play back of youtube videos in my experience.