<commit_before>'use strict';

const MetaPlayer = require('../meta/player');

module.exports = class Player {
  /**
   * Initializes all the necessary elements for audio analysis.
   * These ones should be instantiated just once.
   *
   * @return {null}
   */
  static initialize() {
    this.context  = new AudioContext();
    this.analyser = this.context.createAnalyser();

    this.video_source = this.context.createMediaElementSource(MetaPlayer.video);
    this.audio_source = this.context.createMediaElementSource(MetaPlayer.audio);

    this.video_source.connect(this.analyser);
    this.audio_source.connect(this.analyser);

    this.analyser.connect(this.context.destination);

    this.analyser.fftSize = 128;
  }

  /**
   * Finds the record to play in the cache. Once the record
   * is found, delegates to the `start` method.
   *
   * @param  {String}     id          - The record to play's id.
   * @param  {$=|Record=} playlist    - Optionally the current
   *                                    playlist.
   * @param  {Boolean=}   keep_action - Whether to keep the
   *                                    playing action or not.
   * @return {null}
   */
  static preload(id, playlist, keep_action) {
    // Pause the player if the user clicked on
    // the currently playing item, resume if
    // the player is paused.
    if (this.record && id == this.record.id && !this.paused)
      return this.pause();
    else if (this.record && id == this.record.id && this.paused)
      return this.play();

    // Pretty special feature (TM); hides the search bar when the
    // user starts a new media and the search bar is visible. We
    // assume that they found what they want.
    if ($('.sidebar .search-form').is(':visible'))
      Ui.toggleSearchBar();

    var module = Cache.current.module;
    var action = Cache.current.action;

    MetaModel.findById(id, module, action, playlist).then((record) => {
      if (!keep_action) {
        Cache.playing.module = module;
        Cache.playing.action = action;

        // Reset the current queue's mode
        Queue.setMode(null);
      }

      // Start the playing queue and the media itself.
      Queue.start(record, record.set);
      this.start(record);
    });
  }

  /**
   * Starts the player for a given record.
   *
   * @param  {Media} media - The record to play.
   * @return {null}
   */
  static start(media) {
    this.record = media;

    if (media.service != 'local')<commit_msg>Allow the `.music.bar` elements to be played<commit_after>'use strict';

const MetaPlayer = require('../meta/player');

module.exports = class Player {
  /**
   * Initializes all the necessary elements for audio analysis.
   * These ones should be instantiated just once.
   *
   * @return {null}
   */
  static initialize() {
    this.context  = new AudioContext();
    this.analyser = this.context.createAnalyser();

    this.video_source = this.context.createMediaElementSource(MetaPlayer.video);
    this.audio_source = this.context.createMediaElementSource(MetaPlayer.audio);

    this.video_source.connect(this.analyser);
    this.audio_source.connect(this.analyser);

    this.analyser.connect(this.context.destination);

    this.analyser.fftSize = 128;
  }

  /**
   * Finds the record to play in the cache. Once the record
   * is found, delegates to the `start` method.
   *
   * @param  {String}     id          - The record to play's id.
   * @param  {$=|Record=} playlist    - Optionally the current
   *                                    playlist.
   * @param  {Boolean=}   keep_action - Whether to keep the
   *                                    playing action or not.
   * @return {null}
   */
  static preload(id, playlist, keep_action) {
    // Pause the player if the user clicked on
    // the currently playing item, resume if
    // the player is paused.
    if (this.record && id == this.record.id && !this.paused)
      return this.pause();
    else if (this.record && id == this.record.id && this.paused)
      return this.play();

    // Pretty special feature (TM); hides the search bar when the
    // user starts a new media and the search bar is visible. We
    // assume that they found what they want.
    if ($('.sidebar .search-form').is(':visible'))
      Ui.toggleSearchBar();

    var module = Cache.current.module;
    var action = Cache.current.action;

    MetaModel.findById(id, module, action, playlist).then((record) => {
      if (!keep_action) {
        Cache.playing.module = module;
        Cache.playing.action = action;

        // Reset the current queue's mode
        Queue.setMode(null);
      }

      // Start the playing queue and the media itself.
      Queue.start(record, record.set);
      this.start(record);
    });
  }

  /**
   * Starts the player for a given record.
   *
   * @param  {Media} media - The record to play.
   * @return {null}
   */
  static start(media) {
    if (media instanceof Activity)
      media = media.item;

    this.record = media;

    if (media.service != 'local')
{'fraction_non_alphanumeric': 0.11995225780783768, 'fraction_numerical': 0.0011935548040580863, 'mean_word_length': 2.374496644295302, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2521149', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1461, 'n_words': 437}