播放YouTube HTML5视频嵌入在Android中的WebView [英] Play Youtube HTML5 embedded Video in Android WebView

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

问题描述

我有一个问题,运行的 HTML5的Youtube嵌入 的WebView 。 我想在我的应用程序中播放YouTube视频。我决定使用的WebView代替VideoView,因为我想让我的系统更加灵活,通过网页播放视频。

I am having a problem running a HTML5 Youtube embedded in a WebView. I want to play a Youtube video on my application. I decided to use WebView instead of VideoView, because I want to make my system more flexible to play video from web.

虽然有很多方法来获得对Android播放YouTube,但我会使用YouTube嵌入式版本。 http://www.youtube.com/embed/的 _ __ _ __ _ __ 。因为这是我发现的时候你的android不支持flash的解决方案之一。

Although There are many ways to get play youtube on the android, but I will use the youtube embedded version. "http://www.youtube.com/embed/_________". Because this is one of the solution I found when your android doesn't support flash.

的问题:

The problem:

web视图负荷正常,包括嵌入式的Youtube。但我得到一个黑色的屏幕在YouTube的开始。

The WebView load as normal including the embedded Youtube. But I get a black screen on the youtube at start.

当我点击它。它仅加载第一个图像,但那么它是不是在玩。我试图在Android浏览器中播放时,工程进展顺利,但不是在web视图。

When I click on it. It load the first Image only but then It is not Playing. I tried to play on the android browser, it works smoothly but not in the webView.

任何想法,为什么?

下面是我的code只是一个剪断:

Below is just a snip of my code:

WebView wv = new WebView(getApplicationContext());
wv.getSettings().setPluginState(PluginState.ON);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html");
setContentView(wv);

下面是一些我发现非常有用的资源:

Here are some of the resources that I found very useful:

  • <一个href="http://stackoverflow.com/questions/5817805/how-can-we-play-youtube-embeded-$c$c-in-android-application-using-webview">how我们可以发挥使用的WebView YouTube的内嵌code在Android应用程序?

播放YouTube视频的WebView

<一个href="http://stackoverflow.com/questions/3458765/how-to-embed-a-youtube-clip-in-a-webview-on-android">How嵌入在Android上一个的WebView一个YouTube视频

How to embed a YouTube clip in a WebView on Android

<一个href="http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html">http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html

<一个href="http://www.broken-links.com/2009/10/06/building-html5-video-controls-with-javascript/">http://www.broken-links.com/2009/10/06/building-html5-video-controls-with-javascript/

<一个href="http://www.youtube.com/embed/bHQqvYy5KYo">http://www.youtube.com/embed/bHQqvYy5KYo

感谢您事先的任何支持和帮助:)

Thank you in advance for any support and help :)

更新(2011年6月13日):

我成功加载了 http://m.youtube.com web视图里面,但无法播放任何视频。但是,当我试图加载的URL在我的Andr​​oid浏览器,它可以播放。

I successfully load the http://m.youtube.com inside the WebView, but unable to play any video. But When I tried to load the URL on my Android Browser, it can play.

在这里,我注意到,YouTube网站从我的WebView没有登录。所以,我们如何才能让web视图使用相同的凭证在我的手机我的YouTube帐户?请问它的实际工作?

From here, I notice that the youtube site from my WebView is not signed in. So How can we allow the WebView to use the same credential as my Youtube account in my phone? Will it actually works?

推荐答案

修改

因此​​,从评论的谈话,我们扣除了:

So from the comment conversation we have deducted:

在这个网站:www.youtube.com/html5它说你必须登录,然后选择加入对HTML5视频播放

On this website: www.youtube.com/html5 it says you have to sign in then opt in for HTML5 video playback

这就是为什么你的视频将不会加载,它重定向到一个Flash版本和你的WebView没有闪光灯。

That is why your video will not load, it is redirecting to a flash version and your webview does not have flash.

原始

您重写URL加载所以你的WebView正在使用?

Are you overriding url loading so your webview is being used?

 wv.setWebViewClient(new WebViewClient(){
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            return false;
                    }
            });

您说的视频无法播放,但该网站的负载?

Are you saying the video won't play but the website loads?

您可以尝试躺在至YouTube,并告诉他们你一个不同的浏览器(可能是pretend是Android浏览器),Firefox是:

You could try lying to YouTube and telling them your a different browser (perhaps pretend to be the android browser) Firefox is:

 wv.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.36 (KHTML, like Gecko) Chrome/13.0.766.0 Safari/534.36");

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

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