【问题标题】:youtube embedded url setting not making the video autoplayyoutube 嵌入式 url 设置不使视频自动播放
【发布时间】:2020-06-28 21:14:00
【问题描述】:

我希望嵌入 youtube 的视频在加载后自动播放,但在视频网址似乎不起作用后使用此视频 ?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;
}

视频已正确显示,但不会自动开始。我不知道是哪部分代码导致了这个问题

【问题讨论】:

标签: javascript html youtube


【解决方案1】:

由于muted=1 参数,它没有启动 - 它应该是 mute=1

【讨论】:

    猜你喜欢
    • 2018-12-16
    • 2017-11-03
    • 2016-09-30
    • 1970-01-01
    • 2018-05-25
    • 2021-05-01
    • 2015-05-05
    • 2013-07-21
    相关资源
    最近更新 更多