Javascript DOM HTML Video played Property get

Introduction

Get the first played range of the video in seconds:

Click the button to get the first played range of the video in seconds.

View in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="100" height="100" controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>//from  w  ww  . ja  v a  2s. co  m
<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>

The played property returns a TimeRanges object.

The TimeRanges object represents ranges of the video that has already been played by the user.

A played range is a time-range of played video.

The user gets several played ranges if the video is skipped.

This property is read-only.

TimeRanges Object Properties:

Property Meaning
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.




PreviousNext

Related