Chrome自动播放政策中的自动播放背景视频 [英] Autoplay background video in Chrome Autoplay Policy

查看:398
本文介绍了Chrome自动播放政策中的自动播放背景视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在最新版本的Chrome中,显然自动播放政策已更改,因此这反过来会破坏每个具有应自动播放视频背景的网站 我想知道是否有人可以解决"这个问题? (我相信按钮或进入页面"解决方案将是一种糟糕的解决方法,尤其是对于背景视频而言)

So in the latest chrome apparently the Autoplay Policy has been changed so this in turn breaks every site that has a video background that should autoplay I am wondering if anyone has any smart work arounds that could "solve" the issue? (I believe a button or "enter page" solution would be a terrible way of a work around especially for a background video)

如果用户不与文档进行交互,这就是您现在在控制台中看到的内容:

Here is what you get now in the console if a user doesn't interact with the document:

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

这是Google的更改: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

Here is the change from google: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

推荐答案

在最近的政策更改后,Chrome将不允许自动播放视频.一种简单的解决方案是使视频静音,模拟点击并播放视频.

Chrome will not allow autoplay videos after the recent policy change. An easy solution is to mute the video, simulate a click, then play the video.

HTML

<video id="video" muted loop="loop">

JavaScript

Javascript

// Click a random element
document.getElementById('randomElement').click();
// Play video after click
setTimeout(function(){
    document.getElementById('video').play();
}, 1500);

这篇关于Chrome自动播放政策中的自动播放背景视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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