Javascript examples for DOM HTML Element:Audio
The Audio object represents an HTML <audio> element.
You can access an <audio> element by using getElementById():
<!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 av a 2 s.c om*/ <button onclick="myFunction()">get the 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>