Categories
JavaScript Answers

How to change the playing speed of videos in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *