YouTube iframe嵌入无法在Android上自动播放

前端之家收集整理的这篇文章主要介绍了YouTube iframe嵌入无法在Android上自动播放前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 Android应用程序中使用webView加载YouTube iframe播放器和自动播放视频.它在三星Galaxy S2& S3,但是当在三星Galaxy S4上运行时,试图自动播放时总是导致灰屏.

在Galaxy S4上,无需自动播放即可正常工作,需要用户操作(点击)开始播放
(如果在playerVars中添加“autoplay:1”,则不会发生任何事情).

我试图在onPlayerReady()中调用player.playVideo(),导致这个灰色屏幕:

LogCat还显示了一个奇怪的错误信息:

E/IMGSRV(17004): :0: GetPTLAFormat: Invalid format

自动播放失败.我不知道这个消息是什么;我已经google了,没发现.

以下是WebView的Android代码

WebView wv = (WebView) findViewById(R.id.webview);
WebSettings websettings = wv.getSettings();
websettings.setJavaScriptEnabled(true);
websettings.setDomStorageEnabled(true);
websettings.setDatabaseEnabled(true);
wv.loadUrl(strUrl);
wv.setWebViewClient(new WebViewClient());
wv.setWebChromeClient(new WebChromeClient());
wv.setPadding(0,0);
wv.getSettings().setLoadWithOverviewmode(true);
wv.getSettings().setUseWideViewPort(true);
wv.setVerticalScrollBarEnabled(false);
wv.setHorizontalScrollBarEnabled(false);

这是一个已知问题,还是有自动播放视频的解决方案?谢谢!

解决方法

我认为禁用自动播放正在成为“标准”.

>在iOS Safari中,HTML5标签中的自动播放功能已被禁用. (http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4)
>在Chrome中,自动播放功能也被禁用. (https://code.google.com/p/chromium/issues/detail?id=159336)
>我相信最近版本的默认Android Web浏览器也会发生这种情况.

顺便说一句,你可以试试this

编辑:

链接死了,我发现它在https://lumi.do/p/04x626i1ngvht/how-to-autoplay-html5-video-on-android

How to “autoplay” HTML5 video on Android
Written by Mathias Desloges in Labs on 19/05/11

Have you ever try to play with the new HTML5 video tag on an Android device?
We have and here is an stange issue which we faced.
Let’s set up the context,we want our video starts playing just after the page load complete.
According to the HTML5 specification,we should use the “autoplay” attribute,but it has no effect in Android. So we tried with a little script tha call the play function after the page has loaded:

function callback () { document.querySelector('video').play(); } 
window.addEventListener("load",callback,false);

This reproduces well the behavior of the “autoplay” attribute on a
classic desktop browser,but on an Android browser it fails.
we
tried to attach the prevIoUsly defined “callback()” function to a
click event on a arbitrary node,and the video starts playing well “on
click” (normal behavior). And while continue working on the page html
code,we found the solution!

Don’t ask me why,but after adding the “poster” attribute it works!

原文链接:https://www.f2er.com/html/230772.html

猜你在找的HTML相关文章