Audio currentTime Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

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

Return Value

A Number, representing the current playback time in seconds

The following code shows how to Set time position to 1 second:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials