html video 的 autoplay 不起作用

追格官方小助手/ 2023年02月20日/ WordPress/ 浏览 1102

video 的 autoplay 属性不起作用了!


根据某度的结果,使用 js 让 video 在页面加载后,执行 play()。结果报错:


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


继续百度……


原来,为了对抗网页广告,现在有一个“autoplay协议”,大致如下:


1.muted autoplay始终被允许

 

2.音乐的autoplay 只有在下面集中情况下起作用:


2.1.有用户行为发生像(click,tap,etc).


2.2.对于桌面程序,用户已经提前播放了音频


2.3.对于移动端用户将音频网址home screen.


我的需求是将 video 作为网页背景,所以,直接加上 muted 属性就可以了。


至于,其他情况,感觉 autoplay 貌似已经名存实亡了。


发表评论

暂无评论,抢个沙发...

客服 工单