Detect when an HTML5 video finishes

Brent picture Brent · Apr 30, 2010 · Viewed 309.1k times · Source

How do you detect when a HTML5 <video> element has finished playing?

Answer

Lothereus picture Lothereus · May 21, 2010

You can add an event listener with 'ended' as first param

Like this :

<video src="video.ogv" id="myVideo">
  video not supported
</video>

<script type='text/javascript'>
    document.getElementById('myVideo').addEventListener('ended',myHandler,false);
    function myHandler(e) {
        // What you want to do after the event
    }
</script>