微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐