To change the playing speed of videos in JavaScript, we set the defaultPlaybackRate
and playbackRate
properties.
For instance, we write
document.querySelector("video").defaultPlaybackRate = 2.0;
document.querySelector("video").play();
to select the video element with querySelector
.
Then we set its default playback rate to 2 times the original speed by setting the defaultPlaybackRate
property to 2.0.
Or we write
document.querySelector("video").playbackRate = 3.0;
to set the video’s playbackRate
to 3 times the original speed.