问题描述
我正在尝试让嵌入的 YouTube 视频自动播放.我在参数中设置了 ?autoplay=1 但这似乎已被弃用.不过我没能找到任何关于它的文档.
I am trying to get an embedded YouTube video to autoplay. I have set the ?autoplay=1 in the parameter but this seems to be deprecated. I have not been able to find any documentation on it though.
如何让视频自动播放?
<iframe class="iframe-vid" width="560" height="315" src="https://www.youtube.com/embed/Bey4XXJAqS8?autoplay=1&enablejsapi=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
推荐答案
如果您不介意视频自动播放静音,您可以在 YouTube URL 中添加以下参数:
If you don't mind that the video autoplays muted, you can add the following parameter in the YouTube URL:
&rel=0&mute=1
这是启用和静音自动播放的 iframe
Here is the iframe with autoplay enabled and muted
<iframe class="iframe-vid" width="560" height="315" src="https://www.youtube.com/embed/Bey4XXJAqS8?autoplay=1&enablejsapi=1&rel=0&mute=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
- 在 Google Chrome 版本 72.0.3626.119(官方版本)(32 位)中进行的测试
我真的不知道为什么必须在 URL 中设置静音"选项(并且仅在 Google Chrome 中),因为在 Firefox 和 Edge 中视频自动播放,无需添加 mute
参数.
I really don't know why the "mute" option must be set in the URL (and only in Google Chrome), because in Firefox and Edge the video autoplays without adding the mute
parameter.
这篇关于YouTube 自动播放问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!