youtube embedded url 设置不让视频自动播放
youtube embedded url setting not making the video autoplay
我希望 YouTube 嵌入式视频在加载后自动播放,但在视频 url 之后使用它似乎不起作用
?autoplay=1&loop=1&autopause=0&muted=1
我在 iframe 中显示从用户输入中检索到的视频,如下所示
<iframe width="560" height="315" src="//www.youtube.com/embed/${videoId}?autoplay=1&loop=1&autopause=0&muted=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>`
我还有一个获取 videoId 的函数
function getId(url) {
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
const match = url.match(regExp);
return (match && match[2].length === 11) ?
match[2] :
null;
}
视频显示正确,但没有自动启动。我不知道是哪部分代码导致了这个问题
它没有启动,因为 muted=1
参数 - 它应该是 mute=1
.
我希望 YouTube 嵌入式视频在加载后自动播放,但在视频 url 之后使用它似乎不起作用
?autoplay=1&loop=1&autopause=0&muted=1
我在 iframe 中显示从用户输入中检索到的视频,如下所示
<iframe width="560" height="315" src="//www.youtube.com/embed/${videoId}?autoplay=1&loop=1&autopause=0&muted=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>`
我还有一个获取 videoId 的函数
function getId(url) {
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
const match = url.match(regExp);
return (match && match[2].length === 11) ?
match[2] :
null;
}
视频显示正确,但没有自动启动。我不知道是哪部分代码导致了这个问题
它没有启动,因为 muted=1
参数 - 它应该是 mute=1
.