I'm trying to loop a video by using "videoEnd" attribute

my html

<video id="Video1" width="100%" height="100%">
<source src="cupcakes.mp4" type="video/mp4">
</video>

my JS

var video = document.getElementById("Video1");
video.addEventListener("videoEnd", function() { video.play(); }); 
video.play();

I want the video to loop but it only plays once.
thanks in advance for any help

2 Likes

Hi there attaboy,

try it like this, perhaps…

video.onended=function() {
   video.load();
   video.play();
 }

coothead

1 Like

That did it, thank you so much!

Hi there attaboy,

No problem, you’re very welcome. :sunglasses:

You could, of course, have done it without resorting to javascript…

<video id="Video1" width="100%" height="100%" loop>

coothead

1 Like

Thanks it’s nice to know I have options.

1 Like

So taking coothead’s answer and applying it to your original code you could use:

var video = document.getElementById("Video1");
video.addEventListener("ended", function() { video.load(); video.play(); }); 
video.play();
1 Like

Great, that’s even more better. Now I’ve reached the magic number Three.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.