问题
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