流媒体 YouTube 视频 [英] Streaming Youtube Videos

查看:42
本文介绍了流媒体 YouTube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序来使用流媒体播放 YouTube 视频.

I am writing an application to play youtube videos using streaming.

第一种方法:

我正在使用 GData API 获取视频的 RTSP URL.这是播放 RTSP url 的代码.

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

但是它在 G1 设备和模拟器上都抛出错误(模拟器有一些根据邮件列表的防火墙问题)这是错误信息

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): 命令 PLAYER_INIT 已完成但有错误或信息 PVMF失败

ERROR/PlayerDriver(35): Command PLAYER_INIT completed with an error or info PVMFFailure

第二种方法:

一种获取 3gp 文件路径的黑客方法http://www.youtube.com/get_video?v=&t=<>&<>..获取文件路径后,我可以调用 setVideoURI 并播放美好的.但这是实现要求的一种黑客方式.我也检查了 Youtube 应用程序,它也有黑客的玩法youtube 网址.(用 logcat 检查)

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)

我尝试从 VideoView 更改为 MediaPlayer,但错误没有变化.

I have tried changing from VideoView to MediaPlayer but no change in the error.

有没有一种干净"的方法来做到这一点?

Is there a "Clean" way to do this?

请告诉我您的想法.

推荐答案

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

Sometimes Uri.parse return "null" because cant parse an rtsp protocol instead of http protocol.

使用 Log in logcat Uri.parse(rtspURL).toString() 查看它,您将看不到任何内容.或者只制作 Log.d("tag", Uri.parse); 一样会返回.

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.

尝试寻找另一种解析(创建)Uri 的方法.

Try to find another way to parse (create) an 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();

这篇关于流媒体 YouTube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆