1
votes

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>
2
In safari autoplay for video wont work.. We have to initiate play manually or by script.But in chrome it will work fine. - Vishnu Prasad

2 Answers

3
votes

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.

1
votes

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