On a recent project, I had to trigger a certain behavior when a native HTML5 video had completed playing (i.e. reached the end of the video, manually stopping it should not trigger the behavior). My on page element looked something like:
<video id="primary-video"
src="videos/my-video.mp4"
width="560"
height="315">
</video>
I was able to monitor whether or not this video had reached the end with the following JavaScript
var video = document.getElementById('primary-video');
video.addEventListener('ended', function(e) {
alert('The primary video has played to the end.');
});
Leave a Reply