Audio defaultPlaybackRate Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The defaultPlaybackRate property sets or gets the default playback speed of the audio.

To change the current playback speed, use the playbackRate property.

Set the defaultPlaybackRate property with the following Values

Value Description
number Indicates the default 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

The value 0.0 is invalid and throws a NOT_SUPPORTED_ERR exception

Return Value

A Number, representing the default playback speed

The following code shows how to Set the audio to slow motion by default:

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 the default playback speed?</button>
<button onclick="setPlaySpeed()" type="button">Set video to be play fast</button>

<script>
var x = document.getElementById("myAudio");
function getPlaySpeed() {/*from  ww w .  j a  v  a2s  .  c  o m*/
    console.log(x.defaultPlaybackRate);
}

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

</body>
</html>

Related Tutorials