Javascript DOM HTML Audio buffered Property get

Introduction

Get the first buffered range of the audio in seconds:

Click the button to get the first buffered range of the audio in seconds.

View in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>/*from w  w w . j  a  va2  s . co  m*/

<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myAudio");
  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 stores the user's buffered ranges of the audio.

It is a time-range of buffered audio.

The user can get several buffered ranges if the audio is skipped.

This property is read-only.

TimeRanges Object Properties:

Name Meaning
length the number of buffered ranges in the audio
start the start position of a buffered range
end the end position of a buffered range

The buffered range starts at index 0.




PreviousNext

Related