在Galaxy S4上,无需自动播放即可正常工作,需要用户操作(点击)开始播放
(如果在playerVars中添加“autoplay:1”,则不会发生任何事情).
我试图在onPlayerReady()中调用player.playVideo(),导致这个灰色屏幕:
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/11Have 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!