我有一个带有自动播放和静音选项的嵌入 VIMEO 视频。我正在尝试制作一个自定义功能,让用户通过自定义按钮取消我的视频静音。它工作正常,但在 Chrome 中(尤其是在 Android 中),因为它给了我这个错误:
Unmuting failed and the element was paused instead because the user didn't interact with the document before.
Run Code Online (Sandbox Code Playgroud)
但是如果你阅读他们的文档,它会说:
吸引用户的一种很酷的方法是使用静音自动播放并让他们选择取消静音(请参阅下面的代码片段)。一些网站已经有效地做到了这一点,包括 Facebook、Instagram、Twitter 和 YouTube。
<video id="video" muted autoplay>
<button id="unmuteButton"></button>
<script>
unmuteButton.addEventListener('click', function() {
video.muted = false;
});
</script>
Run Code Online (Sandbox Code Playgroud)
那么,有什么问题呢?我的代码看起来像:
var options = {
id: 316816937,
width: 990,
loop: true,
autoplay: true,
mute: true,
};
var player = new Vimeo.Player('embeddedVideo', options);
player.setVolume(0);
player.on('play', function() {
console.log('played the video!');
});
$(".videoWrapper .cover").click(function () {
$(this).addClass("close");
player.ready().then(function …Run Code Online (Sandbox Code Playgroud)