Javascript DOM HTML Video buffered Property

Introduction

Get the first buffered range of the video in seconds:

Click the button to get the first buffered 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  w w . ja v a  2s  .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.buffered.start(0) + " End: " + x.buffered.end(0);
}
</script>

</body>
</html>

The buffered property returns a TimeRanges object.

The TimeRanges object represents the user's buffered ranges of the video.

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

The user gets several buffered ranges if he/she skips in the video.

This property is read-only.

TimeRanges Object Properties:

ParameterDescription
length get the number of buffered ranges in the video
start(index) get the start position of a buffered range
end(index)get the end position of a buffered range

The first buffered range is index 0.




PreviousNext

Related