我正在得到错误信息..

DOMException: play()失败,因为用户没有首先与文档交互。

..当使用Chrome 66版本在桌面上播放视频时。

我确实发现一个广告开始自动播放在一个网站上,但使用以下HTML:

<video
    title="Advertisement"
    webkit-playsinline="true"
    playsinline="true"
    style="background-color: rgb(0, 0, 0); position: absolute; width: 640px; height: 360px;"
    src="http://ds.serving-sys.com/BurstingRes/Site-2500/Type-16/1ff26f6a-aa27-4b30-a264-df2173c79623.mp4"
    autoplay=""></video>

那么,绕过Chrome v66的自动播放拦截器真的像添加webkit-playsinline="true", playsinline="true"和autoplay=""属性<video>元素一样简单吗?这有什么负面影响吗?


当前回答

公开chrome: / /设置/内容/声音 设置不需要用户手势 重新启动浏览器

其他回答

我改变了我的UI,让用户按下一个按钮来加载网站(当他们点击按钮后,网站加载时,音频播放)

因为他们与DOM交互,然后音频播放!!

就我而言,我必须这么做

 // Initialization in the dom
 // Consider the muted attribute
 <audio id="notification" src="path/to/sound.mp3" muted></audio>


 // in the js code unmute the audio once the event happened
 document.getElementById('notification').muted = false;
 document.getElementById('notification').play();

Chrome需要一个用户交互视频自动播放或通过js (video.play())播放。 但这种互动可以是任何形式的,在任何时刻。 如果你只是在页面上随机点击,视频将自动播放。 然后我解决了这个问题,添加了一个按钮(只在chrome浏览器上),说“启用视频自动播放”。该按钮不做任何事情,只是单击它,是任何进一步视频所需的用户交互。

在我的情况下,它只是一个点击声音,在开始时自动调用(我不介意它是否静音)。所以我用:

const clickSound = new Audio('click.wav');
clickSound.play().catch(function (error) {
    console.log("Chrome cannot play sound without user interaction first")});

来消除错误。

在地址栏中输入Chrome://标志

搜索:播放

播放政策 决定是否允许音频或视频时使用的策略 播放。 - Mac, Windows, Linux, Chrome OS, Android

将其设置为“不需要用户手势”

重新启动Chrome浏览器,你不需要改变任何代码