TL DR: just listen to "timeupdate" :
video.addEventListener("timeupdate", function(){ if(this.currentTime >= 5 * 60) { this.pause(); } });
The usual way to wait for something in JavaScript is to wait for an event or timeout. There is no timeout in this case, the user can pause the video on his own. In this case, the stop will not be at your specific time, but earlier.
Regularly checking the time is also too expensive: you check too often (and therefore waste precious computing power), or not often enough, and therefore you will not stop at the right time.
However, currentTime is a testable property, and, fortunately, there is a timeupdate event for media elements, which is described as follows:
The current playback position has changed as part of normal playback or, which is especially interesting, for example, intermittently.
In conclusion, you can just listen to timeupdate and then check if you passed the sign:
// listen on the event video.addEventListener("timeupdate", function(){ // check whether we have passed 5 minutes, // current time is given in seconds if(this.currentTime >= 5 * 60) { // pause the playback this.pause(); } });
Keep in mind that this will be paused whenever the user tries to skip the last 5 minutes. If you want to allow skips and only initially pause the video for a 5-minute mark, either remove the event listener or enter some flag:
var pausing_function = function(){ if(this.currentTime >= 5 * 60) { this.pause();