Audio playbackRate Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The playbackRate property sets or gets the current playback speed of the audio.

Set the playbackRate property with the following Values

Value Description
playbackspeed Indicates the current playback speed of the audio.

Example values:

  • 1.0 is normal speed, Default value
  • 0.5 is half speed (slower)
  • 2.0 is double speed (faster)
  • -1.0 is backwards, normal speed
  • -0.5 is backwards, half speed

Return Value

A Number, representing the current playback speed

The following code shows how to set the audio to play in slow motion:

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="getPlaySpeed()" type="button">What is playback speed?</button>
<button onclick="setPlaySpeed()" type="button">Set audio to be play fast</button>

<script>
var x = document.getElementById("myAudio");

function getPlaySpeed() {/*from   w w w  .  ja v a2  s  . c  o m*/
    console.log(x.playbackRate);
}

function setPlaySpeed() {
    x.playbackRate = 2;
}
</script>

</body>
</html>

Related Tutorials