0

Hi I look a bit around to find a solution, but as I'm a beginner in javascript I didn't manage to solve the problem:

I have two videos (ogv for Firefox):

    <video loop poster="images/poster.gif">
       <source src="video/bg-4.mp4" type="video/mp4">
       <source src="video/bg-4.ogv" type="video/ogg">
    </video>

I want to check if they are loaded and after autoplay them in loop (as Background Video) I tried this code but it didn't work:

function AutoPlay(){
var v = document.getElementsByTagName("video")[0];
   if ( v.readyState === 4 ) {
        v.play(); 
   }
}

AutoPlay();
  • possible duplicate of [Play infinitely looping video on-load in HTML5](http://stackoverflow.com/questions/10377453/play-infinitely-looping-video-on-load-in-html5) – Andreas Feb 17 '14 at 11:06
  • not really because the problem is to wait that the video is ready and not really the loop... – user3318780 Feb 17 '14 at 11:15
  • `autoplay`: _Instructs the UA to automatically begin playback of the video as soon as it can do so without stopping._, `loop`: _Instructs the UA to seek back to the start of the video upon reaching the end._ - [``](http://www.w3.org/wiki/HTML/Elements/video) – Andreas Feb 17 '14 at 11:24

1 Answers1

1

Just add the this attribute to the video tag:

<video loop poster="images/poster.gif" autoplay>
   <source src="video/bg-4.mp4" type="video/mp4">
   <source src="video/bg-4.ogv" type="video/ogg">
</video>