Javascript examples for DOM HTML Element:Audio
The duration property returns the length of an audio, in seconds.
This property is read-only.
A Number, representing the length of the audio, in seconds.
If no audio is set, "NaN" (Not-a-Number) is returned.
If the audio is streamed and has no predefined length, "Inf" (Infinity) is returned.
The following code shows how to Get the length of an audio:
<!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>/* w ww. j a v a 2 s.c o m*/ <button onclick="myFunction()">get the exact length (duration) of the audio, in seconds</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myAudio").duration; document.getElementById("demo").innerHTML = x; } </script> </body> </html>