我正在尝试将YouTube视频嵌入到我的网站中,以便在页面加载后自动播放。
我当前正在使用:
<iframe width="560" height="315" src="https://www.youtube.com/embed/V4kXFYRhwL0"
frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
但是,视频只有在被点击后才能播放。此代码有什么问题?
链接到网站:http://oxfordcliqr.com/
答案 0 :(得分:0)
将此添加到URL字符串中: ?autoplay = 1&mute = 1
这会将属性自动播放设置为1,将静音设置为1,这样,在页面加载后,视频便开始播放。
由于政策的变化,只有在视频被静音的情况下,自动播放视频才有效。
示例:
<iframe width="560" height="315" src="https://www.youtube.com/embed/V4kXFYRhwL0?autoplay=1&mute=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
答案 1 :(得分:0)
通过autoplay=1
可以在youtube URL中自动播放,而通过mute=1
可以将其静音,这两种方法都可以在页面完全加载后起作用
例如:<iframe width="560" height="315" src="https://www.youtube.com/embed/V4kXFYRhwL0?autoplay=1" ></iframe>
答案 2 :(得分:0)
在iframe网址下方使用自动播放youtube视频
<iframe width="420" height="315" src="https://www.youtube.com/embed/Zm4zpyn0ixw?autoplay=1&mute=1"></iframe>