流媒体 YouTube 视频

发布于 2024-07-25 09:11:56 字数 914 浏览 2 评论 0原文

我正在编写一个使用流媒体播放 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

妳是的陽光 2024-08-01 09:11:56

我们面临着非常相似的问题。

目前我正处于项目的第一步,我正在努力让视频视图简单地工作。
我从这里获取数据: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....

稚气少女 2024-08-01 09:11:56

关注 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

乙白 2024-08-01 09:11:56

我已经使用以下代码显示了 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
}

I've displayed YouTube videos with the following code. I hope its useful, but let me know how it might be improved.

@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
}
猥琐帝 2024-08-01 09:11:56

如果您愿意在新活动中完成这项工作,则以下内容将在设备上运行,但不适用于模拟器:

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")));

獨角戲 2024-08-01 09:11:56

有时 Uri.parse 返回“null”,因为无法解析 rtsp 协议而不是 http 协议。

使用 Log in logcat Uri.parse(rtspURL).toString() 查看,您将看不到任何写入内容。 或者只制作 Log.d("tag", Uri.parse); 并且将返回相同的结果。

尝试找到另一种方法来解析(创建)Uri。

我会尝试这样做并运行:

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();

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 make Log.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:

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();
呆萌少年 2024-08-01 09:11:56

令我印象深刻的是,这种肮脏的方式竟然有效! 如果您有可行的解决方案,请采用它。 我认为目前还没有一种干净的方法可以让 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.

把昨日还给我 2024-08-01 09:11:56

你可以上网吗?
如果没有,请将 Internet 权限添加到清单文件中

 <uses-permission android:name="android.permission.INTERNET" />

,并尝试以下 URI:

rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov

http://www.wowza.com/_h264/BigBuckBunny_175k.mov

do you have the access to the internet?
if not, please add the Internet permission to the manifest file

 <uses-permission android:name="android.permission.INTERNET" />

and also please try these URIs:

rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov

http://www.wowza.com/_h264/BigBuckBunny_175k.mov
爱,才寂寞 2024-08-01 09:11:56

视频上的标题表明它适用于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文