Chrome浏览器的自动播放限制策略

客户:为什么明明我设为自动播放了,却无法自动播放?
我:#@$%^#~
客户:为什么其他浏览器可以自动播放,Chrome浏览器不能自动播,您们产品有问题...
我:^$&^(&^(*%

好吧,我终于找到根源了,分享给大家:

摘录1:Chrome自动播放限制的考量

As you may have noticed, web browsers are moving towards stricter autoplay policies in order to improve the user experience, minimize incentives to install ad blockers, and reduce data consumption on expensive and/or constrained networks. These changes are intended to give greater control of playback to users and to benefit publishers with legitimate use cases.
————————————————

正如您可能已经注意到的,Web浏览器正在朝着更严格的自动播放策略发展,以改善用户体验,最大限度地减少安装广告拦截程序的动机,并减少昂贵的数据流量消耗。这些更改旨在为用户提供更大的播放控制权,并使拥有合法用例的视频发布者受益。

摘录2:Chrome的自动播放政策

Chrome's autoplay policies are simple:
Muted autoplay is always allowed.
Autoplay with sound is allowed if:
The user has interacted with the domain (click, tap, etc.).
On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound.
The user has added the site to their home screen on mobile or installed the PWA on desktop.
Top frames can delegate autoplay permission to their iframes to allow autoplay with sound.
————————————————

  • 静音自动播放总是允许的。
  • 在下列情况下允许使用声音自动播放:
  • 用户已经与域进行了交互(点击,tap等)。
  • 在桌面上,用户的媒体参与指数阈值(MEI)已被越过,这意味着用户以前播放带有声音的视频。
  • 在移动设备上,用户已将该网站添加到主屏幕。
  • 顶部框架可以将自动播放权限授予其iframe以允许自动播放声音。

var promise = document.querySelector('video').play();
 
if (promise !== undefined) {
 promise.then(_ => {
 // Autoplay started!
 }).catch(error => {
 // Autoplay was prevented.
 // Show a "Play" button so that user can start playback.
 });
}
<video id="video" muted autoplay>
<button id="unmuteButton"></button>
 
<script>
 unmuteButton.addEventListener('click', function() {
 video.muted = false;
 });
</script>
作者:阿酷TONY原文地址:https://segmentfault.com/a/1190000043848858

%s 个评论

要回复文章请先登录注册