You can use the timeupdate event listener.
Save the start time and length of time before the variable after the loadedmetadata event.
// Set video element to variable var video = document.getElementById('player1'); var videoStartTime = 0; var durationTime = 0; video.addEventListener('loadedmetadata', function() { videoStartTime = 2; durationTime = 4; this.currentTime = videoStartTime; }, false);
If the current time is longer than the start time and duration, pauses the video.
video.addEventListener('timeupdate', function() { if(this.currentTime > videoStartTime + durationTime){ this.pause(); } });
Paul sham
source share