<commit_before>define(function(require) {
  'use strict';

  var remote = requireNode('remote');
  var globalShortcut = remote.require('global-shortcut');
  var EventEmitter = requireNode('events').EventEmitter;

  var Notifier = require('modules/Notifier');
  var videojs = require('videojs');

  var TrackInfoFetcher = require('backend/TrackInfoFetcher');
  var HistoryManager = require('backend/HistoryManager');
  var L10nManager = require('backend/L10nManager');
  var Searcher = require('backend/Searcher');
  var Tracker = require('backend/Tracker');

  videojs.options.flash.swf = 'dist/vendor/video.js/dist/video-js.swf';

  // This should be a wrapper of Videojs and expose
  // needed events / API out for callee to use
  var Player = function() {
    EventEmitter.call(this);

    this._playingTrack = null;
    this._playerDOM = null;
    this._player = null;

    // TODO
    // If users click on track, we have to update this index ?
    this._pendingTrackIndex = 0;
    this._pendingTracks = [];

    this._bindGlobalShortcuts();
  };

  Player.prototype = Object.create(EventEmitter.prototype);
  Player.constructor = Player;

  Object.defineProperty(Player.prototype, 'playingTrack', {
    enumerable: true,
    configurable: false,
    get: function() {
      return this._playingTrack;
    }
  });

  Player.prototype._bindGlobalShortcuts = function() {
    globalShortcut.register('MediaNextTrack', () => {
      this.playNextTrack();
    });

    globalShortcut.register('MediaPreviousTrack', () => {
      this.playPreviousTrack();
    });

    globalShortcut.register('MediaPlayPause', () => {
      this.playOrPause();
    });

    globalShortcut.register('CmdOrCtrl+Up', () => {
      this.setVolume('up');
    });

    globalShortcut.register('CmdOrCtrl+Down', () => {
      this.setVolume('down');
    });

    globalShortcut.register('Escape', () => {
      this.ready().then(() => {
        this._player.exitFullscreen();
      });
    });
  };

  Player.prototype._getDefaultVideoJSConfig = function() {
    return {
      width: '100%',
      height: 'auto',
      autoplay: false,
      bigPlayButton: false,
      controls: true,
      controlBar: {
        playToggle: false,
        fullscreenToggle: true,
        muteToggle: false
      }
    };
  };

  Player.prototype._addPlayerEvents = function() {
    this._player.on('play', () => {
      this._updateAppHeader('play');
    });

    this._player.on('ended', () => {
      this._updateAppHeader('ended');
      this.playNextTrack();
    });

    this._player.on('error', (error) => {
      Notifier.alert('Unknown errors, please try again');

      // Some hints
      console.log('Please report following errors to us, thanks !');
      console.log(error);
    });
  };

  Player.prototype._toggleSpinner = function(show) {
    // Because _player.loadingSpinner.show() doesn't work in this case,
    // we have to forcely toggle vjs-waiting class to make the loading
    // spinner work.
    var elem = this._player.el();
    if (show) {<commit_msg>fixed #101, lazily register 'esc' key to solve this<commit_after>define(function(require) {
  'use strict';

  var remote = requireNode('remote');
  var globalShortcut = remote.require('global-shortcut');
  var EventEmitter = requireNode('events').EventEmitter;

  var Notifier = require('modules/Notifier');
  var videojs = require('videojs');

  var TrackInfoFetcher = require('backend/TrackInfoFetcher');
  var HistoryManager = require('backend/HistoryManager');
  var L10nManager = require('backend/L10nManager');
  var Searcher = require('backend/Searcher');
  var Tracker = require('backend/Tracker');

  videojs.options.flash.swf = 'dist/vendor/video.js/dist/video-js.swf';

  // This should be a wrapper of Videojs and expose
  // needed events / API out for callee to use
  var Player = function() {
    EventEmitter.call(this);

    this._playingTrack = null;
    this._playerDOM = null;
    this._player = null;

    // TODO
    // If users click on track, we have to update this index ?
    this._pendingTrackIndex = 0;
    this._pendingTracks = [];

    this._bindGlobalShortcuts();
  };

  Player.prototype = Object.create(EventEmitter.prototype);
  Player.constructor = Player;

  Object.defineProperty(Player.prototype, 'playingTrack', {
    enumerable: true,
    configurable: false,
    get: function() {
      return this._playingTrack;
    }
  });

  Player.prototype._bindGlobalShortcuts = function() {
    globalShortcut.register('MediaNextTrack', () => {
      this.playNextTrack();
    });

    globalShortcut.register('MediaPreviousTrack', () => {
      this.playPreviousTrack();
    });

    globalShortcut.register('MediaPlayPause', () => {
      this.playOrPause();
    });

    globalShortcut.register('CmdOrCtrl+Up', () => {
      this.setVolume('up');
    });

    globalShortcut.register('CmdOrCtrl+Down', () => {
      this.setVolume('down');
    });

    // Note
    // we will register/unregister escape key only when fullscreen is
    // triggerd, otherwise, users can't use this key in different applications.
  };

  Player.prototype._getDefaultVideoJSConfig = function() {
    return {
      width: '100%',
      height: 'auto',
      autoplay: false,
      bigPlayButton: false,
      controls: true,
      controlBar: {
        playToggle: false,
        fullscreenToggle: true,
        muteToggle: false
      }
    };
  };

  Player.prototype._addPlayerEvents = function() {
    this._player.on('play', () => {
      this._updateAppHeader('play');
    });

    this._player.on('ended', () => {
      this._updateAppHeader('ended');
      this.playNextTrack();
    });

    this._player.on('fullscreenchange', () => {
      if (this._player.isFullscreen()) {
        globalShortcut.register('Escape', () => {
          this._player.exitFullscreen();
        });
      }
      else {
        globalShortcut.unregister('Escape');
      }
    });

    this._player.on('error', (error) => {
      Notifier.alert('Unknown errors, please try again');

      // Some hints
      console.log('Please report following errors to us, thanks !');
      console.log(error);
    });
  };

  Player.prototype._toggleSpinner = function(show) {
    // Because _player.loadingSpinner.show() doesn't work in this case,
    // we have to forcely toggle vjs-waiting class to make the loading
    // spinner work.
    var elem = this._player.el();
    if (show) {
{'fraction_non_alphanumeric': 0.14410208527855586, 'fraction_numerical': 0.002956738250855898, 'mean_word_length': 2.994406463642014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6418257', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1878, 'n_words': 388}