Html HTML5 视频自动播放不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49822790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML5 Video autoplay not working
提问by Manoj Singh
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
我一直在研究如何在网络和移动设备上将 HTML5 视频实现为背景视频,以下是以下代码 - 它显示但不自动启动,这就是问题所在
<video width="100%" controls autoplay>
<source src="video/342125205.mp4" type="video/mp4">
<source src="video/342125205.ogg" type="video/ogg">
</video>
回答by August
Depending on your Chrome version you might get the new implementation of video autoplay rules:
根据您的 Chrome 版本,您可能会获得视频自动播放规则的新实现:
- 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.
- 始终允许静音自动播放。
- 在以下情况下允许自动播放声音:
- 用户与域进行了交互(单击、点击等)。
- 在桌面上,用户的媒体参与指数阈值已被超过,这意味着用户之前曾播放过有声视频。
- 在移动设备上,用户已将站点添加到他或她的主屏幕。顶级框架可以将自动播放权限委托给它们的 iframe 以允许自动播放声音。
Taken from: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
取自: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>
回答by theplum
I had similar issues with autoplay
not having any effect regardless of usage of muted
. Unexpectedly I had success when specifying autoplay as camel case autoPlay
我有类似的问题,autoplay
无论muted
. 出乎意料的是,我在将自动播放指定为骆驼案例时取得了成功autoPlay