Javascript DOM HTML Audio defaultPlaybackRate Property set

Introduction

Set the audio to slow motion by default:

document.getElementById("myAudio").defaultPlaybackRate = 0.5;

View in separate window

<!DOCTYPE html> 
<html> 
<body> 

<audio id="myAudio" controls>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio><br>
<p id="demo"></p>
<button onclick="getPlaySpeed()" type="button">What is the default playback speed?</button>
<button onclick="setPlaySpeed()" type="button">Set video to be play in slow motion</button>

<script>
var x = document.getElementById("myAudio");
function getPlaySpeed() { /*from   w  w w.jav a 2  s  .  c om*/
  document.getElementById("demo").innerHTML = x.defaultPlaybackRate;
} 

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

</body> 
</html>

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

This property changes the default play back speed, not the current playing one.

To change the current play back speed, use the playbackRate property.

Property Values

Value Description
number Indicates the default playback speed of the audio.

Example values

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



PreviousNext

Related