{"size": 901, "ext": "js", "max_stars_repo_path": "package/src/frontend/mediaPlayer/hooks.js", "max_stars_repo_name": "marcek/pageflow", "max_stars_repo_stars_event_min_datetime": "2015-01-11T14:02:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T14:50:42.000Z", "max_issues_repo_path": "package/src/frontend/mediaPlayer/hooks.js", "max_issues_repo_name": "marcek/pageflow", "max_issues_repo_issues_event_min_datetime": "2015-01-20T10:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T03:11:01.000Z", "max_forks_repo_path": "package/src/frontend/mediaPlayer/hooks.js", "max_forks_repo_name": "marcek/pageflow", "max_forks_repo_forks_event_min_datetime": "2015-01-27T20:05:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T00:28:51.000Z"}
{"max_stars_count": 476, "max_issues_count": 1051, "max_forks_count": 109, "avg_line_length": 22.525, "max_line_length": 60, "alphanum_fraction": 0.6170921199}
export const hooks = function(player, hooks) {
  var originalPlay = player.play;

  player.updateHooks = (newHooks) => {
    hooks = newHooks;
  }
  
  player.play = function(/* args */) {
    var args = arguments;

    player.trigger('beforeplay');
    player.intendToPlay();

    if (hooks.before) {
      return Promise.all([hooks.before()]).then(function() {
        return player.ifIntendingToPlay().then(function() {
          return originalPlay.apply(player, args);
        });
      });
    }
    else{
      return originalPlay.apply(player, args);
    }
  };

  if (player.afterHookListener) {
    player.off('pause', player.afterHookListener);
    player.off('ended', player.afterHookListener);
  }

  player.afterHookListener = ()=>{
    if (hooks.after) {
      hooks.after();
    }
  }
  player.on('pause', player.afterHookListener);
  player.on('ended', player.afterHookListener);

};
