bikegriffith / clappr-playback-rate-plugin

A plugin for the Clappr HTML5 video player that enables variable speed playback (0.5x, 1x, 2x, ...)
MIT License
37 stars 18 forks source link

Incompatible with clappr 0.3.9 #14

Closed bp2008 closed 3 years ago

bp2008 commented 4 years ago

I've tried to get this plugin to work with clappr 0.3.9, and it just failed silently.

After some investigation, I was able to solve it by making this change to the plugin source:

diff

OLD:

  bindEvents() {
    this.listenTo(this.core.mediaControl, Events.CORE_ACTIVE_CONTAINER_CHANGED, this.reload);
    this.listenTo(this.core.mediaControl, Events.MEDIACONTROL_RENDERED, this.render);
    this.listenTo(this.core.mediaControl, Events.MEDIACONTROL_HIDE, this.hideContextMenu);
    this.listenTo(this.core.mediaControl, PlaybackRatePlugin.MEDIACONTROL_PLAYBACKRATE, this.updatePlaybackRate);
  }

  unBindEvents() {
    this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_CONTAINERCHANGED);
    this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_RENDERED);
    this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_HIDE);
  }

NEW:

  bindEvents() {
    this.listenTo(this.core, Events.CORE_ACTIVE_CONTAINER_CHANGED, this.reload);
    this.listenTo(this.core.mediaControl, Events.MEDIACONTROL_RENDERED, this.render);
    this.listenTo(this.core.mediaControl, Events.MEDIACONTROL_HIDE, this.hideContextMenu);
    this.listenTo(this.core.mediaControl, PlaybackRatePlugin.MEDIACONTROL_PLAYBACKRATE, this.updatePlaybackRate);
  }

  unBindEvents() {
    this.stopListening(this.core, Events.CORE_ACTIVE_CONTAINER_CHANGED);
    this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_CONTAINERCHANGED);
    this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_RENDERED);
    this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_HIDE);
  }
bp2008 commented 4 years ago

The event unbinding still looks wrong, but meh... it works now where it didn't before.

bikegriffith commented 4 years ago

Thanks for the report. Feel free to open a PR to improve the event binding/unbinding if you have ideas.

bp2008 commented 4 years ago

Alas, clappr doesn't have good documentation for plugins, so all I know I learned by looking at this and other plugins. It just looks like an event that was never bound is being unbound (Events.MEDIACONTROL_CONTAINERCHANGED), and an event that was bound is not being unbound (PlaybackRatePlugin.MEDIACONTROL_PLAYBACKRATE)