Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my HTML5 video loop (and never trigger the ended event) even though I'm telling it not to?

I have the following HTML:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <video id="video1" preload="metadata" width="1024" height="576" loop="false">
        <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
    </video>

    <script>
        var video = document.getElementById('video1');
        video.addEventListener("ended", function() {
            alert('Ended');
        });

        video.play();
    </script>
</body>
</html>

In chrome and firefox the video loops endlessly. Attaching listeners to the pause or ended events show these never actually get fired.

I need to know when a video has ended (and I need it to stop on ending). What am I doing wrong?

like image 314
KallDrexx Avatar asked Sep 28 '13 03:09

KallDrexx


2 Answers

Apparently loop='false' still causes it to loop, and you have to completely remove the loop attribute to prevent looping. Ended never gets called if the video is set to loop.

like image 144
KallDrexx Avatar answered Sep 26 '22 19:09

KallDrexx


    video.addEventListener("ended",function(){
        console.log("the video is end");
    },false);
like image 29
popotang Avatar answered Sep 22 '22 19:09

popotang