视频自动播放在Safari和Chrome桌面浏览器中不起作用 [英] Video auto play is not working in Safari and Chrome desktop browser
本文介绍了视频自动播放在Safari和Chrome桌面浏览器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< video height =我花了相当多的时间试图弄清为什么要嵌入视频。 256loop =trueautoplay =autoplaycontrols =controlsid =vid>
< source type =video / mp4src =video_file.mp4>< / source>
< source type =video / oggsrc =video_file.ogg>< / source>
< / video>
在FireFox中加载页面后自动开始播放,但无法在基于Webkit的浏览器中自动播放。这只发生在一些随机页面上。到目前为止,我无法找到原因。我怀疑一些未封闭的标签或CMS编辑器创建的广泛的JS。
解决方案
< / video>
< script>
document.getElementById('vid')。play();
< / script>
...不是很漂亮,但有些作用。
I spent quite a lot of time trying to figure out why video embedded like here:
<video height="256" loop="true" autoplay="autoplay" controls="controls" id="vid">
<source type="video/mp4" src="video_file.mp4"></source>
<source type="video/ogg" src="video_file.ogg"></source>
</video>
starts playing automatically once the page is loaded in FireFox but but cannot do autoplay in Webkit based browsers. This only happened on some random pages. So far I was unable to find the cause. I suspect some unclosed tags or extensive JS created by CMS editors.
解决方案
The best fix I could get was adding this code just after the </video>
<script>
document.getElementById('vid').play();
</script>
...not pretty but somehow works.
这篇关于视频自动播放在Safari和Chrome桌面浏览器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文