HTML Audio & Video
HTML DOM Audio defaultPlaybackRate Property
The defaultPlaybackRate property sets or returns the default playback speed of a media element. This is the speed the media reverts to at the next playback, as opposed to playbackRate, which is the speed in effect right now.
Definition and Usage
A value of 1.0 is normal speed, 0.5 is half speed and 2.0 is double speed. defaultPlaybackRate stores the intended default; when playback is reset or restarted, the current playbackRate is set back to this default value.
Syntax
// Get the value
let rate = mediaElement.defaultPlaybackRate;
// Set the value
mediaElement.defaultPlaybackRate = 1.5;It is a number. Negative values are allowed by the spec to indicate reverse playback, though support for reverse playback is inconsistent across browsers.
Example
<video id="myVideo" width="320" controls>
<source src="movie.mp4" type="video/mp4">
</video>
<script>
const video = document.getElementById("myVideo");
// Media should default to 1.5x speed
video.defaultPlaybackRate = 1.5;
video.load(); // apply the default at (re)load
console.log(video.playbackRate); // 1.5 after load
console.log(video.defaultPlaybackRate); // 1.5
</script>Setting defaultPlaybackRate before load() makes the media start at that speed. Changing playbackRate afterwards only affects the current session and leaves defaultPlaybackRate untouched.
Use playbackRate to change speed immediately during playback. Use defaultPlaybackRate to set the speed the element resets to, which the browser also applies through the ratechange event flow.
