如何处理“未捕获(承诺)DOMException:play() 失败,因为用户没有先与文档交互."在 Chrome 66 的桌面上? [英] How to handle "Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first." on Desktop with Chrome 66?

查看:115
本文介绍了如何处理“未捕获(承诺)DOMException:play() 失败,因为用户没有先与文档交互."在 Chrome 66 的桌面上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误消息..

未捕获(承诺)DOMException:play() 失败,因为用户没有先与文档交互.

Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.

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

..when trying to play video on desktop using Chrome version 66.

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

I did find an ad that began playback automatically on a website however using the following 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="" 属性?这有什么负面影响吗?

So is by-passing Chrome v66's autoplay blocker really as easy as just adding the webkit-playsinline="true", playsinline="true", and autoplay="" attributes to the <video> element? Are there any negative consequences to this?

推荐答案

要使 html 5 元素在 chrome 66 更新后自动播放,您只需将 muted 属性添加到视频元素.

To make the autoplay on html 5 elements work after the chrome 66 update you just need to add the muted property to the video element.

所以你当前的视频 HTML

So your current video HTML

<video
    title="Advertisement"
    webkit-playsinline="true"
    playsinline="true"
    style="background-color: rgb(0, 0, 0); position: absolute; width: 640px; height: 360px;"
    src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
    autoplay=""></video>

只需要muted="muted"

<video
    title="Advertisement"
    style="background-color: rgb(0, 0, 0); position: absolute; width: 640px; height: 360px;"
    src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
    autoplay="true"
    muted="muted"></video>

我相信 chrome 66 更新试图阻止标签在用户标签上产生随机噪音.这就是静音属性使自动播放再次工作的原因.

I believe the chrome 66 update is trying to stop tabs creating random noise on the users tabs. That's why the muted property make the autoplay work again.

这篇关于如何处理“未捕获(承诺)DOMException:play() 失败,因为用户没有先与文档交互."在 Chrome 66 的桌面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆