Javascript examples for DOM HTML Element:Audio
The played property returns a TimeRanges object, which represents ranges of the audio that has already been played by the user.
The user gets several played ranges if he/she skips in the audio.
This property is read-only.
Type | Description |
---|---|
TimeRanges Object | Represents the played parts of the audio. |
TimeRanges Object Properties:
The first played range is index 0
The following code shows how to get the first played range (part) of the audio in seconds:
<!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 w w w . j av a 2 s. c o 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>