• Skip to primary navigation
  • Skip to content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Twitter GitHub
You are here: Home / Dev Tips / Detect when Native HTML5 Video Finishes Playing

Warning! This is a draft, not a finalized post. See full draft disclosure.

Detect when Native HTML5 Video Finishes Playing

Last updated on October 9, 2018 by Sal Ferrarello

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.');
});

Share this post:

TwitterFacebookLinkedinEmailReddit

Filed Under: Dev Tips, Draft, Programming Tagged With: JavaScript

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2019 · Genesis Framework · WordPress · Log in