mozilla / popcorn-js

The HTML5 Media Framework. (Unmaintained. See https://github.com/menismu/popcorn-js for activity)
MIT License
2.14k stars 632 forks source link

playbackRate() not implemented for HTMLYouTubeVideoElement #400

Open georgemarshall opened 10 years ago

georgemarshall commented 10 years ago

The YouTube player API offers the following hooks for adjusting the playback rate. If no one beats me to this, my plan will be to circle back in ~48 hours and create a pull request that adds this the wrapper.

https://developers.google.com/youtube/js_api_reference

player.getPlaybackRate();
player.setPlaybackRate(suggestedRate);
player.getAvailablePlaybackRates();
ScottDowne commented 10 years ago

I tried this ages ago, and found that in most cases getAvailablePlaybackRates would only return an array of 1. :(

jmgirven commented 10 years ago

I'm not sure if you guys ever got this working or not, but I was just experimenting with this too. In popcorn-complete.js 1.5.6, HTMLYouTubeVideoElement, line 6479: Object.defineProperties, I just added a getter and setter for playbackRate and getAvailablePlaybackRates:

  playbackRate: {
    get: function() {
      return player.getPlaybackRate();   
    },
    set: function( aValue ) {
      player.setPlaybackRate(aValue);
      self.dispatchEvent( "ratechange" );
    }
  },

  availablePlaybackRates: {
    get: function() {
      return player.getAvailablePlaybackRates();
    }
  },

The videos I have been looking at tend to have available playback rates of [0.25, 0.5, 1, 1.25, 1.5, 2]. I know YouTube doesn't provide this for all videos though, so you should check the list before setting a new playbackRate.

You can then change the playbackRate using e.g:

var rate = popcornElement.media.availablePlaybackRates[0];
popcornElement.media.playbackRate = rate;

Does that work for you too?