Javascript examples for DOM HTML Element:Audio
The currentTime property sets or gets the current position in seconds of the audio playback.
When setting this property, the playback will jump to the specified position.
Set the currentTime property with the following Values
Value | Description |
---|---|
seconds | Sets the position for the playback of the audio, in seconds |
A Number, representing the current playback time in seconds
The following code shows how to Set time position to 1 second:
<!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><br> <button onclick="getCurTime()" type="button">Get current time position</button> <button onclick="setCurTime()" type="button">Set time position to 1 second</button> <script> var x = document.getElementById("myAudio"); function getCurTime() {/*from w ww.j a va 2 s. c o m*/ console.log(x.currentTime); } function setCurTime() { x.currentTime = 1; } </script> </body> </html>