本文介绍了HTML5视频自动播放不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在研究如何将HTML5视频作为 背景 网络和移动视频,以下代码如下: 它显示但不自动启动,这就是问题
I have been looking into how to implement HTML5 videos as a background video on web and mobile, below is the following code- it displays but not autostarts, this is the problem
<video width="100%" controls autoplay>
<source src="video/342125205.mp4" type="video/mp4">
<source src="video/342125205.ogg" type="video/ogg">
</video>
推荐答案
根据您的Chrome版本,您可能会获得视频自动播放规则的新实现:
Depending on your Chrome version you might get the new implementation of video autoplay rules:
- 始终允许静音的自动播放.
- 在以下情况下,允许自动播放声音:
- 用户已与域进行了交互(单击,点击等).
- 在桌面上,已经超过了用户的媒体参与指数"阈值,这意味着该用户以前曾播放有声视频.
- 在移动设备上,用户已将该网站添加到他或她的主屏幕中.顶部框架可以将自动播放权限委派给其内嵌框架,以允许自动播放声音.
- Muted autoplay is always allowed.
- Autoplay with sound is allowed if:
- 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 play video with sound.
- On mobile, the user has added the site to his or her home screen.Top frames can delegate autoplay permission to their iframes to allow autoplay with sound.
来自: https://developers.google.com /web/updates/2017/09/autoplay-policy-changes
因此您可以尝试将其静音:
So you can try it muted:
<video width="100%" controls autoplay muted> <source src="video/342125205.mp4" type="video/mp4"> <source src="video/342125205.ogg" type="video/ogg"> </video>
这篇关于HTML5视频自动播放不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!