Sha256: c9229079d3c22dff3ad658f93a7edcaad0ee3e3524655cf8e153e935a9172803

Contents?: true

Size: 1.95 KB

Versions: 58

Compression:

Stored size: 1.95 KB

Contents

//= require_self
//= require ./audio/player_pool
//= require ./audio/multi_player

/**
 * Playing audio files.
 * @alias pageflow.audio
 * @member
 */
pageflow.Audio = function(options) {
  this.getSources = options.getSources || function(audioFileId) {
    return options.audioFiles[audioFileId] || '';
  };

  /**
   * Creates a player for the given audio file.
   *
   * @param {string|number} audioFileId
   *   Id of the audio file to play. The id can be of the form
   *   `"5.suffix"` to distinguish multiple occurences of the same
   *   audio file for example inside a pageflow.Audio.PlayerPool;
   *
   * @param {Object} [options]
   *   Options to pass on player creation
   *
   * @static
   */
  this.createPlayer = function(audioFileId, options) {
    var sources = this.getSources(removeSuffix(audioFileId));

    if (sources) {
      return new pageflow.AudioPlayer(sources, _.extend({
        volumeFading: true
      }, options || {}));
    }
    else {
      return new pageflow.AudioPlayer.Null();
    }
  };

  /**
   * Create a `MultiPlayer` to play and fade between multiple audio
   * files.
   *
   * @param {Object} [options]
   *   All options supported by pageflow.AudioPlayer can be passed.
   *
   * @param {number} [options.fadeDuration]
   *   Time in milliseconds to fade audios in and out.
   *
   * @param {boolean} [options.playFromBeginning=false]
   *   Always restart audio files from the beginning.
   *
   * @param {boolean} [options.rewindOnChange=false]
   *   Play from beginning when changing audio files.
   *
   * @return {pageflow.Audio.MultiPlayer}
   */
  this.createMultiPlayer = function(options) {
    return new pageflow.Audio.MultiPlayer(
      new pageflow.Audio.PlayerPool(this, options),
      options
    );
  };

  function removeSuffix(id) {
    if (!id) {
      return id;
    }

    return parseInt(id.toString().split('.')[0], 10);
  }
};

pageflow.Audio.setup = function(options) {
  pageflow.audio = new pageflow.Audio(options);
};

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
pageflow-14.5.2 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.2 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.1 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.0 app/assets/javascripts/pageflow/audio.js
pageflow-14.5.1 app/assets/javascripts/pageflow/audio.js
pageflow-14.5.0 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.0.rc2 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.0.rc1 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.0.beta4 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.0.beta3 app/assets/javascripts/pageflow/audio.js
pageflow-14.4.0 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.0.beta2 app/assets/javascripts/pageflow/audio.js
pageflow-15.0.0.beta1 app/assets/javascripts/pageflow/audio.js
pageflow-14.3.0 app/assets/javascripts/pageflow/audio.js
pageflow-14.2.1 app/assets/javascripts/pageflow/audio.js
pageflow-14.2.0 app/assets/javascripts/pageflow/audio.js
pageflow-14.1.1 app/assets/javascripts/pageflow/audio.js
pageflow-14.1.0 app/assets/javascripts/pageflow/audio.js
pageflow-14.0.0 app/assets/javascripts/pageflow/audio.js
pageflow-14.0.0.rc2 app/assets/javascripts/pageflow/audio.js