Search code examples
javascriptvideowebkitautoplaymediacontroller

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


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>

Solution

  • 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