流媒体 YouTube 视频
我正在编写一个使用流媒体播放 YouTube 视频的应用程序。
第一种方法:
我使用 GData API 获取视频的 RTSP URL。 这是播放 RTSP url 的代码。
VideoView mVideoView = new VideoView(this);
setContentView(mVideoView);
mVideoView.setVideoURI(Uri.parse("rtsp://rtsp2.youtube.com/CiILENy73wIaGQkDwpjrUxOWQBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
mVideoView.start();
但它在 G1 设备和模拟器上都会抛出错误(模拟器有一些 根据邮件列表的防火墙问题) 以下是错误消息
ERROR/PlayerDriver(35): 命令 PLAYER_INIT 完成但有错误或 info PVMFFailure
第二种方法:
一种获取 3gp 文件路径的 hack 方法 http://www.youtube.com/get_video?v=&t=< ><>.. 获取文件路径后,我可以调用 setVideoURI 并播放 美好的。 但这是实现要求的一种黑客方法。 我也检查了 Youtube 应用程序,它也有 hack 方式玩 youtube url。(用 logcat 检查)
我尝试从 VideoView 更改为 MediaPlayer 但错误没有变化。
有没有一种“干净”的方法来做到这一点?
请让我知道你的想法。
I am writing an application to play youtube videos using streaming.
First method:
I am getting the RTSP URL to the video using GData APIs.
Here is the code to play the RTSP url.
VideoView mVideoView = new VideoView(this);
setContentView(mVideoView);
mVideoView.setVideoURI(Uri.parse("rtsp://rtsp2.youtube.com/CiILENy73wIaGQkDwpjrUxOWQBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
mVideoView.start();
But it throws error on both G1 device and emulator (Emulator has some
firewall problem as per mailing list)
Here is the error message
ERROR/PlayerDriver(35): Command PLAYER_INIT completed with an error or
info PVMFFailure
Second method:
A hack way to get the path of 3gp file from
http://www.youtube.com/get_video?v=&t=<>&<>..
After getting the file path and I can call setVideoURI and it plays
fine. But it is a hack way to achieve the requirement.
I have checked the Youtube App also, it also does the hack way to play
the youtube url.(Checked with logcat)
I have tried changing from VideoView to MediaPlayer but no change in the error.
Is there a "Clean" way to do this?
Please let me know your thoughts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我们面临着非常相似的问题。
目前我正处于项目的第一步,我正在努力让视频视图简单地工作。
我从这里获取数据:http://gdata.youtube.com/demo/ 并且我正在测试所有视频链接。
RTSP 3GP 视频确实是低质量视频......并且无法访问 mp4(高质量)视频。 我真的不知道如何让它发挥作用,因为我认为 MP4 流仅适用于高级开发人员......
we faced a very similar problem.
At the moment I'm at the first step of my project and I'm trying to make the videoview simply works.
I'm taking data from here: http://gdata.youtube.com/demo/ and I'm testing all the videos links.
RTSP 3GP videos are really really really low quality video.... and there is no way to access to mp4 (good quality) videos. I really don't know how to make it works because I think that MP4 streams are available only to premium devs....
关注 Youtube API
我认为这也使用 youtube 应用程序(您不这样做)不想)
但只要参考一下也许你会找到一些解决它的关键
Throw eye over Youtube API
I think this also use youtube app(Which you don't want)
But just refer may be you will find some key to solve it
我已经使用以下代码显示了 YouTube 视频。 我希望它有用,但请让我知道如何改进它。
I've displayed YouTube videos with the following code. I hope its useful, but let me know how it might be improved.
如果您愿意在新活动中完成这项工作,则以下内容将在设备上运行,但不适用于模拟器:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www. youtube.com/watch?v=cxLG2wtE7TM")));
If you're willing to do the work in a new activity, the following will work on a device but not on the emulator:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));
有时 Uri.parse 返回“null”,因为无法解析 rtsp 协议而不是 http 协议。
使用 Log in logcat
Uri.parse(rtspURL).toString()
查看,您将看不到任何写入内容。 或者只制作Log.d("tag", Uri.parse);
并且将返回相同的结果。尝试找到另一种方法来解析(创建)Uri。
我会尝试这样做并运行:
Sometimes Uri.parse return "null" because cant parse an rtsp protocol instead of http protocol.
Look it with an Log in logcat
Uri.parse(rtspURL).toString()
and you will see nothing written. or only makeLog.d("tag", Uri.parse);
and the same will be return.Try to find another way to parse (create) an Uri.
I'd try with that and run:
令我印象深刻的是,这种肮脏的方式竟然有效! 如果您有可行的解决方案,请采用它。 我认为目前还没有一种干净的方法可以让 RTSP 流在 SDK 中工作。
I'm impressed that the dirty way works at all! If you've got a working solution, go with it. I don't think there's a clean way to get RTSP streaming working in the SDK yet.
你可以上网吗?
如果没有,请将 Internet 权限添加到清单文件中
,并尝试以下 URI:
do you have the access to the internet?
if not, please add the Internet permission to the manifest file
and also please try these URIs:
视频上的标题表明它适用于 Android。 因此,尝试一个好的视频链接来进行试验。 这是我使用的:
rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov
我在 Nexus 和 Samsung 平板电脑上工作得很好。
The header on the video indicates it does work for Android. So, try a good video link to experiment with. Here is one that I use:
rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov
I works great on Nexus and Samsung tablets.