<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The ontimeupdate</h2>
<p>Attach a "timeupdate" event to a video element.</p>
<p>When the user plays the video, or skips to a new position, a function will display the position (in seconds) of the playback:</p>
<video id="myVideo" width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video><br>
<button onclick="setCurTime()" type="button">Set time position to 5 seconds</button>
<p id="demo"></p>
<script>
const video = document.getElementById("myVideo");
video.addEventListener("timeupdate", getCurTime);
function getCurTime() {
document.getElementById("demo").innerHTML = "The playback position is " + video.currentTime + " seconds.";
}
function setCurTime() {
video.currentTime = 5;
}
</script>
</body>
</html>