javascript - Youtube 在手机上嵌入自动播放

标签 javascript html reactjs youtube-api

我使用 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/

相关文章:

javascript - 启用 Chrome Headless 时 Dusk 测试失败

javascript - 如何使用 jquery 查找特定类的总 tr?

javascript - 使用 e.preventDefault();不工作

javascript - 如果 React 组件库需要 React 作为对等依赖项,我该如何使用它来制作 Preact?

reactjs - 如何在loopback.js中处理客户端 react 路由

javascript - CodePen React 代码无法加载我的渐变背景

VS 中 JavaScript 未定义错误

javascript - jQuery 对象从 html 表转换为 Chartist 图表的两个一维数组

javascript - 响应式幻灯片导航按钮

reactjs - "This express is not callable. Type ' bool 值 ' has no call signatures"