Javascript DOM onseeked Event use currentTime property of the Video Object

Introduction

Using the currentTime property of the Video Object to display the current playtime position when the user is finished moving to a new position:

In this example, we attach a "seeked" event to the video element.

The currentTime property returns the current position in seconds of the video playback.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Move to a new position in the video.</p>

<video id="myVideo" controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>/* w w  w. ja v a  2s.  co  m*/

<p>Seeked to position: <span id="demo"></span></p>

<script>
// Get the video element with id="myVideo"
var x = document.getElementById("myVideo");

x.addEventListener("seeked", myFunction);

function myFunction() {
  document.getElementById("demo").innerHTML = x.currentTime;
}
</script>
</body>
</html>



PreviousNext

Related