Question

I would like to know how to speed up a youtube video 2x without the user clicking on the HTML5 (of the video), but instead by modifying the URL.

For example, I know how to watch video starting at a specific time by appending to the URL the parameter &t=1m1s (for 1 minute and one second). Is it possible to use a similar method to speed up the video 2x?

What parameters should I add to the URL to watch video in double speed (I'm using html5)?

Was it helpful?

Solution

There's no way to change playback speed by URL arguments.

Anyway, if you're working with HTML, you can take advantage of the YouTube Player iFrame API.

Here's how to configure your player with all the JavaScript: https://developers.google.com/youtube/iframe_api_reference#Getting_Started

And here's the function you're looking for to set playback speed: https://developers.google.com/youtube/iframe_api_reference#Playback_rate

So you can edit your onPlayerReady function like this:

function onPlayerReady(event) {
  player.setPlaybackRate(2); // This is what you're looking for
  event.target.playVideo();
}

You can of course pass on step 5 of the documentation as this will stop your video from playing after six seconds.

If you have trouble setting that up, I'll edit a JSFiddle later (couldn't do it at work as my Flash plugin won't launch).

Update :

Here's the JSFiddle working fine with this code exactly: http://jsfiddle.net/jpreynat/e11oy0eu/

OTHER TIPS

I was trying to do this exact same thing earlier this week.

A solution purely from a URL parameter isn't possible. (or if it is, it's not documentation here: https://developers.google.com/youtube/player_parameters)

I came accros this JSFiddle by Johan Preynat: http://jsfiddle.net/jpreynat/e11oy0eu/

Worked for me, so hopefully it'll be useful for you too

HTML

<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>

JavaScript

// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
//    after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '390',
        width: '640',
        videoId: 'M7lc1UVf-VE',
        events: {
            'onReady': onPlayerReady
        }
    });
}

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
    player.setPlaybackRate(2);
    event.target.playVideo();
}

See also the YouTube documentation on this: https://developers.google.com/youtube/iframe_api_reference

Can you inject a shift > or < from users input via url or easier javascript? Maybe its easier to force the hot key press from the users end.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top