user3318780
user3318780

Reputation: 1

Video HTML5 / wait until Readystate === 4 then playvideo in loop

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();

Upvotes: 0

Views: 906

Answers (1)

user1693593
user1693593

Reputation:

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>

Upvotes: 1

Related Questions