Video loop autoplay won't work on Chrome/safari (webkit bug)

二次信任 提交于 2020-01-06 01:20:34

问题


Hi guys I am trying to have my video autoplay and loop in a slider but some how it's not playing on chrome and safari. I find out webkit browsers have a bug that stops the video autoplay function when it's restyled...

Here's the video and the page. (works on firefox) http://dustintong.com/projects.html#ts

I think you have to re-trigger the .play() Not sure what I did wrong. New to javascript... Here's the code below.

JS

var myVideo = document.querySelector('video');
var mediaController = myVideo.controller;

mediaController.play();

HTML

<div id="video">
<video src="images/7-4s.mp4" autoplay loop muted> 
</video> </div>

回答1:


In safari, autoplay works just fine. If you put this <video src="images/7-4s.mp4" autoplay loop muted> you don't need any js. You can try this plugin https://github.com/videojs/video.js




回答2:


I guess the best solution to this is adding this script just after your video tag--

<script type="text/javascript">
    document.getElementById('videoid').play();
</script>

Abit cheesy but works well :) You can also try setting preload attribute to true.



来源:https://stackoverflow.com/questions/31422040/video-loop-autoplay-wont-work-on-chrome-safari-webkit-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!