Get the first played range of the audio in seconds:
Click the button to get the first played range of the audio in seconds.
<!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 av a2 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.played.start(0) + " End: " + x.played.end(0); } </script> </body> </html>
The played
property returns a TimeRanges
object.
The TimeRanges
object tells the ranges of the audio played.
A played range is a time-range of played audio.
The user will have several played ranges if the audio is skipped.
This property is read-only.
TimeRanges Object Properties:
Value | Meaning |
---|---|
length | get the number of played ranges in the audio |
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