YouTube上的iframe嵌入影片不能在Android上自动播放 [英] YouTube iframe embeds cannot autoplay on Android

查看:1773
本文介绍了YouTube上的iframe嵌入影片不能在Android上自动播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的Andr​​oid应用程序一个web视图加载YouTube的iframe的播放器和自动播放视频。它工作正常,在三星Galaxy S2和放大器; S3,但是当对三星Galaxy S4运行时,它试图自动播放的时候总是会导致灰色屏幕。

在银河S4,它工作正常没有自动播放,需要用户操作(点击)开始播放 (如果加入自动播放:1什么都没有发生在playerVars)

我试着打player.playVideo()的onPlayerReady(),它导致了这个灰色的屏幕:

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

  E / IMGSRV(17004):0:GetPTLAFormat:无效的格式
 

在没有自动播放。我不知道这消息是关于;我GOOGLE了一下,发现什么都没有。

下面是WebView功能的安卓code:

 的WebView WV =(web视图)findViewById(R.id.webview);
WebSettings websettings = wv.getSettings();
websettings.setJavaScriptEnabled(真正的);
websettings.setDomStorageEnabled(真正的);
websettings.setDatabaseEnabled(真正的);
wv.loadUrl(strUrl);
wv.setWebViewClient(新WebViewClient());
wv.setWebChromeClient(新WebChromeClient());
wv.setPadding(0,0,0,0);
。wv.getSettings()setLoadWithOverviewMode(真正的);
。wv.getSettings()setUseWideViewPort(真正的);
wv.setVerticalScrollBarEnabled(假);
wv.setHorizo​​ntalScrollBarEnabled(假);
 

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

解决方案

我想禁用自动播放正成为一个标准。

  • 在iOS的Safari浏览器,在自动播放HTML5标签被禁用。 (<一href="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" rel="nofollow">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://$c$c.google.com/ P /铬/问题/详细信息?ID = 159336

  • 我相信同样的情况,使用默认的Andr​​oid Web浏览器的最新版本。

顺便说一句,你可以尝试

编辑:

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

  

如何自动播放HTML5视频在Android
  在实验室写的马蒂亚斯Desloges在19/05/11

  你有没有尝试在Android设备上使用新的HTML5视频标签玩?
  我们这里是我们面临的一个STANGE问题。
  让我们设置的背景下,我们希望我们的视频在启动后的页面加载完成比赛。
  根据HTML5规范,我们应该用自动播放属性,但它在Android中没有任何影响。因此,我们试着用一个小脚本塔调用播放功能后,页面加载:

 回调函数(){document.querySelector('视频')播放()。 }
window.addEventListener(加载,回调,假);
 

  

这也再现了自动播放属性的行为上   经典的桌面浏览器,但在Android浏览器,它会失败。
我们   试图附加的previously定义的回调()函数以一个   点击任意一个节点上的事件,并在视频开始玩好​​   点击(正常行为)。尽管继续工作的HTML页面   code,我们找到了解决办法!

     

     

不要问我为什么,但添加了大字报的属性后,它的工作!

I'm using a webView in my Android app to load YouTube iframe player and auto play videos. It works fine on Samsung Galaxy S2 & S3, but when runs on Samsung Galaxy S4, it always results in gray screen when trying to auto play.

On Galaxy S4, it works fine without autoplay, needs user action(click) to start playing (Nothing happened if adding "autoplay:1" in playerVars).

I tried to call player.playVideo() in onPlayerReady(), it resulted in this gray screen:

The LogCat also shows a weird error message:

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

when failed to autoplay. I don't know what this message is about; I've googled it and found nothing.

Here's the Android code of WebView:

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, 0, 0);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.setVerticalScrollBarEnabled(false);
wv.setHorizontalScrollBarEnabled(false);

Is this a known issue or if there's any solution to autoplay the video? Thanks!

解决方案

I think disabling autoplay is becoming a "standard".

By the way, you could try this

EDIT:

As the link is dead, I found it in 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!

这篇关于YouTube上的iframe嵌入影片不能在Android上自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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