javascript Youtube 在移动设备上嵌入自动播放
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48399390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Youtube embed autoplay on mobile
提问by jaroApp
I use React to set iframe with youtube video on page in correct size. All works well but for mobiles doesn't work autoplay option.
我使用 React 在页面上以正确大小设置带有 youtube 视频的 iframe。一切正常,但对于手机而言,自动播放选项不起作用。
What is interesting for page, what I have as example video it works perfect.
什么是有趣的页面,我有什么作为示例视频它完美无缺。
<iframe type="text/html" allowTransparency="true" height="100%" width="100%" preload="metadata" gesture="media" allow="encrypted-media" className="autoplay-iframe"
src={`https://www.youtube.com/embed/`+this.props.autoplay+`?autoplay=1&version=3&html5=1&hd=1&controls=0&loop=1&playlist=`+this.props.autoplay+`&playsinline=1&rel=0&showinfo=0&modestbranding=1&related=0&enablejsapi=1&origin=`+window.location.hostname} frameborder="0"></iframe>
above is my iframe code. I cut some part of iframe code but there are just style in styles attribute. It isn't important for autoplay. The same finally url for other page works. I'm not sure why. Any hints how I can solve this problem?
上面是我的 iframe 代码。我剪掉了 iframe 代码的一部分,但在样式属性中只有样式。这对于自动播放并不重要。其他页面的最终 url 相同。我不知道为什么。任何提示我如何解决这个问题?
Thanks in advance.
提前致谢。
回答by MαπμQμαπkγVπ.0
You will not be able to implement this, since it is intentionally disabled to all mobile devices. The reason is for the user to save cellular data. It is also cited in this post.
您将无法实现此功能,因为它已对所有移动设备有意禁用。原因是为了用户保存蜂窝数据。这篇文章中也引用了这一点。
The reason that video autoplay doesn't work is simple. The feature is deliberately disabledin both iOS and Android for mobile devices. The reason this is done is to save mobile users money. Such devices (especially mobile phones) often use data connections that charge by bandwidth. They have data limits and going over results in a fee.
视频自动播放不起作用的原因很简单。该功能在移动设备的 iOS 和 Android 中都被故意禁用。这样做的原因是为了节省移动用户的钱。此类设备(尤其是移动电话)通常使用按带宽收费的数据连接。他们有数据限制,并且会产生费用。
This statement was also supported with the following SO post.
以下 SO 帖子也支持此声明。
回答by Bree
The rules have changed so most new mobiles will now let you autoplay, but most video streaming sites like youtube and vimeo haven't enabled the functionality yet. The reason the html5 video worked but the iframe didn't is because youtube disabled it.
规则已更改,因此大多数新手机现在都可以让您自动播放,但大多数视频流网站(如 youtube 和 vimeo)尚未启用该功能。html5 视频有效但 iframe 无效的原因是因为 youtube 禁用了它。
回答by JaeDee
The reason that video autoplay doesn't work is simple. The feature is deliberately disabled in both iOS and Android for mobile devices. The reason this is done is to save mobile users money. Such devices (especially mobile phones) often use data connections that charge by bandwidth.
视频自动播放不起作用的原因很简单。该功能在移动设备的 iOS 和 Android 中都被故意禁用。这样做的原因是为了节省移动用户的钱。此类设备(尤其是移动电话)通常使用按带宽收费的数据连接。

