我使用 React 将 iframe 与页面上的 youtube 视频设置为正确的大小。一切正常,但对于手机来说,自动播放选项不起作用。
页面有什么有趣的地方,我有什么作为示例视频,它完美无缺。
<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>
以上是我的 iframe 代码。 我削减了部分 iframe 代码,但样式属性中只有样式。这对自动播放并不重要。 其他页面的最终网址相同。我不确定为什么。有什么提示可以解决这个问题吗?
提前致谢。
最佳答案
您将无法实现此功能,因为它已被有意禁用于所有移动设备。原因是用户要保存蜂窝数据。它也在 this post 中被引用.
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. They have data limits and going over results in a fee.
以下 SO 帖子也支持此声明。
关于javascript - Youtube 在手机上嵌入自动播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48399390/