如何在Android视频查看播放YouTube视频? [英] How to play Youtube videos in Android Video View?

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

问题描述

我开发一个Android应用程序,需要一个YouTube视频播放器嵌入它。我成功地得到了来自API的RTSP视频网址,但在尝试加载此RTSP URL在我的Andr​​oid视频查看,它说无法播放这部影片。。 previously我开发的这种方法的类似的应用,并在那个时候工作得很好,但它也没有现在加载。

I am developing an android application which requires a youtube video player embedded within it. I successfully got the RTSP video URL from the API, but while trying to load this rtsp url in my android video view, it says "Can't play this video.". Previously I developed a similar application in this method, and it worked fine at that time, but it also failing to load now.

我知道这一点,我得到了正确的RTSP URL的API。 <$c$c>rtsp://v6.cache6.c.youtube.com/CiULENy73wIaHAlV9VII3c64lRMYESARFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp

I'm sure about that, I'm getting the correct RTSP url from the API. rtsp://v6.cache6.c.youtube.com/CiULENy73wIaHAlV9VII3c64lRMYESARFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp

下面是我的活动code:

Here is my activity code:

    mVideoURL = getIntent().getStringExtra("EXT_URL");
    Log.i("VIDEO URL", " " + mVideoURL);

    MediaController mc = new MediaController(this);
    mVideoStreamView = (VideoView) findViewById(R.id.vidPlayer);

    mVideoStreamView.setVideoURI(Uri.parse(mVideoURL));
    mVideoStreamView.setMediaController(mc);
    mVideoStreamView.requestFocus();
    mVideoStreamView.start();

修改 从logcat中发现了一些额外的信息:

EDIT Found some additional information from the logcat:

ARTSPConnection(6607): status: RTSP/1.0 200 OK
ASessionDescription(6607): v=0
ASessionDescription(6607): o=GoogleStreamer 378992432 328144046 IN IP4 74.125.213.182
ASessionDescription(6607): s=Video
ASessionDescription(6607): c=IN IP4 0.0.0.0
ASessionDescription(6607): b=AS:29
ASessionDescription(6607): t=0 0
ASessionDescription(6607): a=control:*
ASessionDescription(6607): a=range:npt=0-1703.000000
ASessionDescription(6607): m=video 0 RTP/AVP 98
ASessionDescription(6607): b=AS:17
ASessionDescription(6607): a=rtpmap:98 H263-2000/90000
ASessionDescription(6607): a=control:trackID=0
ASessionDescription(6607): a=cliprect:0,0,144,176
ASessionDescription(6607): a=framesize:98 176-144
ASessionDescription(6607): a=fmtp:98 profile=0;level=10
ASessionDescription(6607): m=audio 0 RTP/AVP 99
ASessionDescription(6607): b=AS:12
ASessionDescription(6607): a=rtpmap:99 AMR/8000/1
ASessionDescription(6607): a=control:trackID=1
ASessionDescription(6607): a=fmtp:99 octet-align
ARTSPConnection(6607): status: RTSP/1.0 200 OK
ARTSPConnection(6607): status: RTSP/1.0 200 OK
ARTSPConnection(6607): status: RTSP/1.0 200 OK
ARTSPConnection(6607): status: RTSP/1.0 200 OK
ARTSPConnection(6607): status: RTSP/1.0 200 OK
ASessionDescription(6607): v=0
ASessionDescription(6607): o=GoogleStreamer 1299458498 503248054 IN IP4 74.125.213.182
ASessionDescription(6607): s=Video
ASessionDescription(6607): c=IN IP4 0.0.0.0
ASessionDescription(6607): b=AS:29
ASessionDescription(6607): t=0 0
ASessionDescription(6607): a=control:*
ASessionDescription(6607): a=range:npt=0-1703.000000
ASessionDescription(6607): m=video 0 RTP/AVP 98
ASessionDescription(6607): b=AS:17
ASessionDescription(6607): a=rtpmap:98 H263-2000/90000
ASessionDescription(6607): a=control:trackID=0
ASessionDescription(6607): a=cliprect:0,0,144,176
ASessionDescription(6607): a=framesize:98 176-144
ASessionDescription(6607): a=fmtp:98 profile=0;level=10
ASessionDescription(6607): m=audio 0 RTP/AVP 99
ASessionDescription(6607): b=AS:12
ASessionDescription(6607): a=rtpmap:99 AMR/8000/1
ASessionDescription(6607): a=control:trackID=1
ASessionDescription(6607): a=fmtp:99 octet-align
ARTSPConnection(6607): status: RTSP/1.0 461 Unsupported Transport
ARTSPConnection(6607): status: RTSP/1.0 461 Unsupported Transport

请给我建议的方式来加载YouTube视频在Android的视频查看。

Please suggest me a way to load youtube videos in android video view.

在此先感谢...

修改 刚刚签入其他设备上,HTC Desire(2.2)。在code正常工作。 我想了解一下思维,会是怎样与Nexus One的问题(4.1)??

EDIT Just checked in another device, HTC Desire (2.2). The code worked fine. I'm wondering about thinking, What will be the problem with Nexus (4.1)??

推荐答案

正如我无法找到任何方式来加载视频视图中的RTSP URL(所有设备及放大器; Android的版本),我解决我的问题与另一个工作周围。我用了一个web视图,以在其中嵌入YouTube播放器,而这种方法在所有测试设备的工作很好。

As I can't find any way to load the rtsp URL in video view (for all devices & android versions), I solved my problem with another work around. I used a webview to embed the youtube player within it, and this method working nicely in all tested devices.

下面是我的code:

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.loadUrl("http://www.youtube.com/embed/" + videoID + "?autoplay=1&vq=small");
mWebView.setWebChromeClient(new WebChromeClient());

非常感谢您为您的所有帮助球员。

Thank you very much for all your help guys.

这篇关于如何在Android视频查看播放YouTube视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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