Video played Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video

Description

The played property returns a TimeRanges object, which represents ranges of the video that has already been played by the user.

This property is read-only.

Return Value

Type Description
TimeRanges Object Represents the played parts of the video.

TimeRanges Object Properties:

  • length - get the number of played ranges in the video
  • start(index) - get the start position of a played range
  • end(index) - get the end position of a played range

The first played range is index 0

The following code shows how to get the first played range (part) of the video in seconds:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>//from   w w  w  . ja  va2 s  .  c om

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myVideo");
    document.getElementById("demo").innerHTML = "Start: " + x.played.start(0) + " End: " + x.played.end(0);
}
</script>

</body>
</html>

Related Tutorials