How do I change the playback speed of the currently playing YouTube video using JavaScript and an HTML5 player?

If I watch a YouTube video on a YouTube website using an HTML5 player, what JavaScript code can I use to get the video playback speed and change it to another parameter?

In particular, I need this code for the Greasemonkey script I'm working on, so the JavaScript code will be executed in the user's browser.

I know I can do the following:

document.getElementsByClassName('html5-main-video')[0].playbackRate = 2.0

And this will double the playback speed, but it will not change the drop-down box for the "Speed" field of the YouTube player to "2.0", which I would like to do if possible.

+7
javascript html5 youtube greasemonkey video
source share
1 answer

After playing with HTML, I just faked .click() . This seems to be the best way. I was looking a bit for the YouTube API, but just found documents for embedding YouTube videos on my page. I also played with HTML5 video, for example $('#video').playbackRate = 3.0 , and then you could basically change the speed to whatever you want, but that will not affect the drop-down list, which may be useful, if you want to change it to a different speed.

Here's the jQuery code:

$('#ytp-menu-speed').parent().find('.ytp-button:contains("1.5")').click()

Change 1.5 to any speed you need, if this is an option that YouTube provides.

+5
source share

All Articles