Android 流媒体 YouTube 视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1007695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Streaming Youtube Videos
提问by Vinay
I am writing an application to play youtube videos using streaming.
我正在编写一个应用程序来使用流播放 youtube 视频。
First method:
第一种方法:
I am getting the RTSP URL to the video using GData APIs. Here is the code to play the RTSP url.
我正在使用 GData API 获取视频的 RTSP URL。这是播放 RTSP 网址的代码。
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
但是它在 G1 设备和模拟器上都抛出错误(根据邮件列表,模拟器有一些防火墙问题)这是错误消息
ERROR/PlayerDriver(35): Command PLAYER_INIT completed with an error or info PVMFFailure
错误/PlayerDriver(35):命令 PLAYER_INIT 已完成,但出现错误或信息 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)
一种从http://www.youtube.com/get_video?v=&t=<>&<>.. 获取3gp 文件路径的黑客方法 。获取文件路径后,我可以调用 setVideoURI 并且播放正常。但这是实现要求的一种黑客方式。我也检查了 Youtube 应用程序,它也可以播放 youtube 网址。(用 logcat 检查)
I have tried changing from VideoView to MediaPlayer but no change in the error.
我尝试从 VideoView 更改为 MediaPlayer,但错误没有变化。
Is there a "Clean" way to do this?
有没有“干净”的方法来做到这一点?
Please let me know your thoughts.
请让我知道你的想法。
回答by emmby
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")));
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));
回答by XanXa
Sometimes Uri.parse return "null" because cant parse an rtsp protocol instead of http protocol.
有时 Uri.parse 会返回“null”,因为无法解析 rtsp 协议而不是 http 协议。
Look it with an Log in logcat Uri.parse(rtspURL).toString()
and you will see nothing written. or only make Log.d("tag", Uri.parse);
and the same will be return.
使用 Log in logcat 查看它,Uri.parse(rtspURL).toString()
您将看不到任何内容。或者只做Log.d("tag", Uri.parse);
,同样会返回。
Try to find another way to parse (create) an Uri.
尝试寻找另一种解析(创建)Uri 的方法。
I'd try with that and run:
我会尝试并运行:
String urlVideo = <your rtspURL>
VideoView video = (VideoView)findViewById(R.id.VideoView01);
Log.d(tag , urlVideo);
video.setVideoURI(Uri.parse(urlVideo));
MediaController mc = new MediaController(this);
video.setMediaController(mc);
video.requestFocus();
video.start();
mc.show();
回答by haseman
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.
我印象深刻的是,肮脏的方式根本有效!如果你有一个可行的解决方案,那就去吧。我不认为有一种干净的方法可以让 RTSP 流在 SDK 中工作。
回答by StErMi
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.
目前我正处于项目的第一步,我正在努力使视频视图简单地工作。我正在从这里获取数据:http: //gdata.youtube.com/demo/并且我正在测试所有视频链接。
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....
RTSP 3GP 视频真的是非常低质量的视频......并且无法访问 mp4(高质量)视频。我真的不知道如何使它工作,因为我认为 MP4 流仅适用于高级开发人员......
回答by edwin
Throw eye over Youtube API
I think this also use youtube app(Which you don't want)
我认为这也使用 youtube 应用程序(你不想要的)
But just refer may be you will find some key to solve it
但只是参考可能你会找到一些解决它的关键
回答by Droid Chris
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:
视频的标题表明它适用于 Android。所以,尝试一个好的视频链接来试验。这是我使用的一种:
rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov
rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov
I works great on Nexus and Samsung tablets.
我在 Nexus 和三星平板电脑上工作得很好。
回答by Albert Chen
do you have the access to the internet? if not, please add the Internet permission to the manifest file
你能上网吗?如果没有,请在清单文件中添加 Internet 权限
<uses-permission android:name="android.permission.INTERNET" />
and also please try these URIs:
还请尝试这些 URI:
rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov
http://www.wowza.com/_h264/BigBuckBunny_175k.mov
回答by reaper
I've displayed YouTube videos with the following code. I hope its useful, but let me know how it might be improved.
我用以下代码显示了 YouTube 视频。我希望它有用,但让我知道如何改进它。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=...")));
}
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
}