Javascript DOM HTML Audio seekable Property get

Introduction

Get the first seekable range of the audio in seconds:

Click the button to get the first seekable 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 ww w . j  a  va  2s  .  com
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

The seekable property returns a TimeRanges object.

The TimeRanges object returns the ranges of the audio available for seeking.

A seekable range is a time-range of audio which the user can move playback position to.

This property is read-only.

TimeRanges Object Object Properties:

Value Meaning
lengthget the number of seekable ranges in the audio
start(index) get the start position of a seekable range
end(index) get the end position of a seekable range

The first seekable range is index 0




PreviousNext

Related