Audio buffered Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The buffered property returns a TimeRanges object, which represents the user's buffered ranges of the audio.

This property is read-only.

Return Value

Type Description
TimeRanges Object Represents the buffered parts of the audio.

TimeRanges Object Properties:

  • length - get the number of buffered ranges in the audio
  • 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

The following code shows how to Get the first buffered range (part) of the audio in seconds:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls>
  <source src="your.ogg" type="audio/ogg">
  <source src="your.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>/*from   ww  w .  j a  va 2  s  .com*/

<button onclick="myFunction()">get the first buffered range (part) of the audio in seconds</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>

Related Tutorials