code
stringlengths 10
343k
| docstring
stringlengths 36
21.9k
| func_name
stringlengths 1
3.35k
| language
stringclasses 1
value | repo
stringlengths 7
58
| path
stringlengths 4
131
| url
stringlengths 44
195
| license
stringclasses 5
values |
---|---|---|---|---|---|---|---|
p._setPlaybackResource = function (value) {
this._playbackResource = value;
if (this._duration == 0 && this._playbackResource) { this._setDurationFromSource(); }
return this;
}; | Please use {{#crossLink "AbstractSoundInstance/playbackResource:property"}}{{/crossLink}} directly as a property
@method _setPlaybackResource
@protected
@param {Object} value The new playback resource.
@return {AbstractSoundInstance} Returns reference to itself for chaining calls
@since 0.6.0
* | p._setPlaybackResource ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getPlaybackResource = function () {
return this._playbackResource;
}; | Please use {{#crossLink "AbstractSoundInstance/playbackResource:property"}}{{/crossLink}} directly as a property
@method _getPlaybackResource
@protected
@param {Object} value The new playback resource.
@return {Object} playback resource used for playing audio
@since 0.6.0
* | p._getPlaybackResource ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getLoop = function () {
return this._loop;
}; | Please use {{#crossLink "AbstractSoundInstance/loop:property"}}{{/crossLink}} directly as a property
@method _getLoop
@protected
@return {number}
@since 0.6.0
* | p._getLoop ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setLoop = function (value) {
if(this._playbackResource != null) {
// remove looping
if (this._loop != 0 && value == 0) {
this._removeLooping(value);
}
// add looping
else if (this._loop == 0 && value != 0) {
this._addLooping(value);
}
}
this._loop = value;
}; | Please use {{#crossLink "AbstractSoundInstance/loop:property"}}{{/crossLink}} directly as a property
@method _setLoop
@protected
@param {number} value The number of times to loop after play.
@since 0.6.0 | p._setLoop ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._sendEvent = function (type) {
var event = new createjs.Event(type);
this.dispatchEvent(event);
}; | A helper method that dispatches all events for AbstractSoundInstance.
@method _sendEvent
@param {String} type The event type
@protected | p._sendEvent ( type ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._cleanUp = function () {
clearTimeout(this.delayTimeoutId); // clear timeout that plays delayed sound
this._handleCleanUp();
this._paused = false;
createjs.Sound._playFinished(this); // TODO change to an event
}; | Clean up the instance. Remove references and clean up any additional properties such as timers.
@method _cleanUp
@protected | p._cleanUp ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._interrupt = function () {
this._cleanUp();
this.playState = createjs.Sound.PLAY_INTERRUPTED;
this._sendEvent("interrupted");
}; | The sound has been interrupted.
@method _interrupt
@protected | p._interrupt ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._playFailed = function () {
this._cleanUp();
this.playState = createjs.Sound.PLAY_FAILED;
this._sendEvent("failed");
}; | Play has failed, which can happen for a variety of reasons.
Cleans up instance and dispatches failed event
@method _playFailed
@private | p._playFailed ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleSoundComplete = function (event) {
this._position = 0; // have to set this as it can be set by pause during playback
if (this._loop != 0) {
this._loop--; // NOTE this introduces a theoretical limit on loops = float max size x 2 - 1
this._handleLoop();
this._sendEvent("loop");
return;
}
this._cleanUp();
this.playState = createjs.Sound.PLAY_FINISHED;
this._sendEvent("complete");
}; | Audio has finished playing. Manually loop it if required.
@method _handleSoundComplete
@param event
@protected | p._handleSoundComplete ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleSoundReady = function () {
// plugin specific code
}; | Handles starting playback when the sound is ready for playing.
@method _handleSoundReady
@protected | p._handleSoundReady ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._updateVolume = function () {
// plugin specific code
}; | Internal function used to update the volume based on the instance volume, master volume, instance mute value,
and master mute value.
@method _updateVolume
@protected | p._updateVolume ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._updatePan = function () {
// plugin specific code
}; | Internal function used to update the pan
@method _updatePan
@protected
@since 0.6.0 | p._updatePan ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._updateStartTime = function () {
// plugin specific code
}; | Internal function used to update the startTime of the audio.
@method _updateStartTime
@protected
@since 0.6.1 | p._updateStartTime ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._updateDuration = function () {
// plugin specific code
}; | Internal function used to update the duration of the audio.
@method _updateDuration
@protected
@since 0.6.0 | p._updateDuration ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setDurationFromSource = function () {
// plugin specific code
}; | Internal function used to get the duration of the audio from the source we'll be playing.
@method _updateDuration
@protected
@since 0.6.0 | p._setDurationFromSource ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._calculateCurrentPosition = function () {
// plugin specific code that sets this.position
}; | Internal function that calculates the current position of the playhead and sets this._position to that value
@method _calculateCurrentPosition
@protected
@since 0.6.0 | p._calculateCurrentPosition ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._updatePosition = function () {
// plugin specific code
}; | Internal function used to update the position of the playhead.
@method _updatePosition
@protected
@since 0.6.0 | p._updatePosition ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._removeLooping = function (value) {
// plugin specific code
}; | Internal function called when looping is removed during playback.
@method _removeLooping
@param {number} value The number of times to loop after play.
@protected
@since 0.6.0 | p._removeLooping ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._addLooping = function (value) {
// plugin specific code
}; | Internal function called when looping is added during playback.
@method _addLooping
@param {number} value The number of times to loop after play.
@protected
@since 0.6.0 | p._addLooping ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._pause = function () {
// plugin specific code
}; | Internal function called when pausing playback
@method _pause
@protected
@since 0.6.0 | p._pause ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._resume = function () {
// plugin specific code
}; | Internal function called when resuming playback
@method _resume
@protected
@since 0.6.0 | p._resume ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleStop = function() {
// plugin specific code
}; | Internal function called when stopping playback
@method _handleStop
@protected
@since 0.6.0 | p._handleStop ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleCleanUp = function() {
// plugin specific code
}; | Internal function called when AbstractSoundInstance is being cleaned up
@method _handleCleanUp
@protected
@since 0.6.0 | p._handleCleanUp ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleLoop = function () {
// plugin specific code
}; | Internal function called when AbstractSoundInstance has played to end and is looping
@method _handleLoop
@protected
@since 0.6.0 | p._handleLoop ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
(function () {
"use strict";
// Constructor:
var AbstractSoundInstance = function (src, startTime, duration, playbackResource) {
this.EventDispatcher_constructor();
// public properties:
/**
* The source of the sound.
* @property src
* @type {String}
* @default null
*/
this.src = src;
/**
* The unique ID of the instance. This is set by {{#crossLink "Sound"}}{{/crossLink}}.
* @property uniqueId
* @type {String} | Number
* @default -1
*/
this.uniqueId = -1;
/**
* The play state of the sound. Play states are defined as constants on {{#crossLink "Sound"}}{{/crossLink}}.
* @property playState
* @type {String}
* @default null
*/
this.playState = null;
/**
* A Timeout created by {{#crossLink "Sound"}}{{/crossLink}} when this AbstractSoundInstance is played with a delay.
* This allows AbstractSoundInstance to remove the delay if stop, pause, or cleanup are called before playback begins.
* @property delayTimeoutId
* @type {timeoutVariable}
* @default null
* @protected
* @since 0.4.0
*/
this.delayTimeoutId = null;
// TODO consider moving delay into AbstractSoundInstance so it can be handled by plugins
// private properties
// Getter / Setter Properties
// OJR TODO find original reason that we didn't use defined functions. I think it was performance related
/**
* The volume of the sound, between 0 and 1.
*
* The actual output volume of a sound can be calculated using:
* <code>myInstance.volume * createjs.Sound._getVolume();</code>
*
* @property volume
* @type {Number}
* @default 1
*/
this._volume = 1;
Object.defineProperty(this, "volume", {
get: this._getVolume,
set: this._setVolume
});
this.getVolume = createjs.deprecate(this._getVolume, "AbstractSoundInstance.getVolume");
this.setVolume = createjs.deprecate(this._setVolume, "AbstractSoundInstance.setVolume");
/**
* The pan of the sound, between -1 (left) and 1 (right). Note that pan is not supported by HTML Audio.
*
* Note in WebAudioPlugin this only gives us the "x" value of what is actually 3D audio
* @property pan
* @type {Number}
* @default 0
*/
this._pan = 0;
Object.defineProperty(this, "pan", {
get: this._getPan,
set: this._setPan
});
this.getPan = createjs.deprecate(this._getPan, "AbstractSoundInstance.getPan");
this.setPan = createjs.deprecate(this._setPan, "AbstractSoundInstance.setPan");
/**
* Audio sprite property used to determine the starting offset.
* @property startTime
* @type {Number}
* @default 0
* @since 0.6.1
*/
this._startTime = Math.max(0, startTime || 0);
Object.defineProperty(this, "startTime", {
get: this._getStartTime,
set: this._setStartTime
});
this.getStartTime = createjs.deprecate(this._getStartTime, "AbstractSoundInstance.getStartTime");
this.setStartTime = createjs.deprecate(this._setStartTime, "AbstractSoundInstance.setStartTime");
/**
* Sets or gets the length of the audio clip, value is in milliseconds.
*
* @property duration
* @type {Number}
* @default 0
* @since 0.6.0
*/
this._duration = Math.max(0, duration || 0);
Object.defineProperty(this, "duration", {
get: this._getDuration,
set: this._setDuration
});
this.getDuration = createjs.deprecate(this._getDuration, "AbstractSoundInstance.getDuration");
this.setDuration = createjs.deprecate(this._setDuration, "AbstractSoundInstance.setDuration");
/**
* Object that holds plugin specific resource need for audio playback.
* This is set internally by the plugin. For example, WebAudioPlugin will set an array buffer,
* HTMLAudioPlugin will set a tag, FlashAudioPlugin will set a flash reference.
*
* @property playbackResource
* @type {Object}
* @default null
*/
this._playbackResource = null;
Object.defineProperty(this, "playbackResource", {
get: this._getPlaybackResource,
set: this._setPlaybackResource
});
if(playbackResource !== false && playbackResource !== true) { this._setPlaybackResource(playbackResource); }
this.getPlaybackResource = createjs.deprecate(this._getPlaybackResource, "AbstractSoundInstance.getPlaybackResource");
this.setPlaybackResource = createjs.deprecate(this._setPlaybackResource, "AbstractSoundInstance.setPlaybackResource");
/**
* The position of the playhead in milliseconds. This can be set while a sound is playing, paused, or stopped.
*
* @property position
* @type {Number}
* @default 0
* @since 0.6.0
*/
this._position = 0;
Object.defineProperty(this, "position", {
get: this._getPosition,
set: this._setPosition
});
this.getPosition = createjs.deprecate(this._getPosition, "AbstractSoundInstance.getPosition");
this.setPosition = createjs.deprecate(this._setPosition, "AbstractSoundInstance.setPosition");
/**
* The number of play loops remaining. Negative values will loop infinitely.
*
* @property loop
* @type {Number}
* @default 0
* @public
* @since 0.6.0
*/
this._loop = 0;
Object.defineProperty(this, "loop", {
get: this._getLoop,
set: this._setLoop
});
this.getLoop = createjs.deprecate(this._getLoop, "AbstractSoundInstance.getLoop");
this.setLoop = createjs.deprecate(this._setLoop, "AbstractSoundInstance.setLoop");
/**
* Mutes or unmutes the current audio instance.
*
* @property muted
* @type {Boolean}
* @default false
* @since 0.6.0
*/
this._muted = false;
Object.defineProperty(this, "muted", {
get: this._getMuted,
set: this._setMuted
});
this.getMuted = createjs.deprecate(this._getMuted, "AbstractSoundInstance.getMuted");
this.setMuted = createjs.deprecate(this._setMuted, "AbstractSoundInstance.setMuted");
/**
* Pauses or resumes the current audio instance.
*
* @property paused
* @type {Boolean}
*/
this._paused = false;
Object.defineProperty(this, "paused", {
get: this._getPaused,
set: this._setPaused
});
this.getPaused = createjs.deprecate(this._getPaused, "AbstractSoundInstance.getPaused");
this.setPaused = createjs.deprecate(this._setPaused, "AbstractSoundInstance.setPaused");
// Events
/**
* The event that is fired when playback has started successfully.
* @event succeeded
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
/**
* The event that is fired when playback is interrupted. This happens when another sound with the same
* src property is played using an interrupt value that causes this instance to stop playing.
* @event interrupted
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
/**
* The event that is fired when playback has failed. This happens when there are too many channels with the same
* src property already playing (and the interrupt value doesn't cause an interrupt of another instance), or
* the sound could not be played, perhaps due to a 404 error.
* @event failed
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
/**
* The event that is fired when a sound has completed playing but has loops remaining.
* @event loop
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
/**
* The event that is fired when playback completes. This means that the sound has finished playing in its
* entirety, including its loop iterations.
* @event complete
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @since 0.4.0
*/
};
var p = createjs.extend(AbstractSoundInstance, createjs.EventDispatcher);
// Public Methods:
/**
* Play an instance. This method is intended to be called on SoundInstances that already exist (created
* with the Sound API {{#crossLink "Sound/createInstance"}}{{/crossLink}} or {{#crossLink "Sound/play"}}{{/crossLink}}).
*
* <h4>Example</h4>
*
* var myInstance = createjs.Sound.createInstance(mySrc);
* myInstance.play({interrupt:createjs.Sound.INTERRUPT_ANY, loop:2, pan:0.5});
*
* Note that if this sound is already playing, this call will still set the passed in parameters.
* <b>Parameters Deprecated</b><br />
* The parameters for this method are deprecated in favor of a single parameter that is an Object or {{#crossLink "PlayPropsConfig"}}{{/crossLink}}.
*
* @method play
* @param {Object | PlayPropsConfig} props A PlayPropsConfig instance, or an object that contains the parameters to
* play a sound. See the {{#crossLink "PlayPropsConfig"}}{{/crossLink}} for more info.
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p.play = function (props) {
var playProps = createjs.PlayPropsConfig.create(props);
if (this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this.applyPlayProps(playProps);
if (this._paused) { this._setPaused(false); }
return;
}
this._cleanUp();
createjs.Sound._playInstance(this, playProps); // make this an event dispatch??
return this;
};
/**
* Stop playback of the instance. Stopped sounds will reset their position to 0, and calls to {{#crossLink "AbstractSoundInstance/resume"}}{{/crossLink}}
* will fail. To start playback again, call {{#crossLink "AbstractSoundInstance/play"}}{{/crossLink}}.
*
* If you don't want to lose your position use yourSoundInstance.paused = true instead. {{#crossLink "AbstractSoundInstance/paused"}}{{/crossLink}}.
*
* <h4>Example</h4>
*
* myInstance.stop();
*
* @method stop
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p.stop = function () {
this._position = 0;
this._paused = false;
this._handleStop();
this._cleanUp();
this.playState = createjs.Sound.PLAY_FINISHED;
return this;
};
/**
* Remove all external references and resources from AbstractSoundInstance. Note this is irreversible and AbstractSoundInstance will no longer work
* @method destroy
* @since 0.6.0
*/
p.destroy = function() {
this._cleanUp();
this.src = null;
this.playbackResource = null;
this.removeAllEventListeners();
};
/**
* Takes an PlayPropsConfig or Object with the same properties and sets them on this instance.
* @method applyPlayProps
* @param {PlayPropsConfig | Object} playProps A PlayPropsConfig or object containing the same properties.
* @since 0.6.1
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p.applyPlayProps = function(playProps) {
if (playProps.offset != null) { this._setPosition(playProps.offset) }
if (playProps.loop != null) { this._setLoop(playProps.loop); }
if (playProps.volume != null) { this._setVolume(playProps.volume); }
if (playProps.pan != null) { this._setPan(playProps.pan); }
if (playProps.startTime != null) {
this._setStartTime(playProps.startTime);
this._setDuration(playProps.duration);
}
return this;
};
p.toString = function () {
return "[AbstractSoundInstance]";
};
// get/set methods that allow support for IE8
/**
* Please use {{#crossLink "AbstractSoundInstance/paused:property"}}{{/crossLink}} directly as a property.
* @method _getPaused
* @protected
* @return {boolean} If the instance is currently paused
* @since 0.6.0
*/
p._getPaused = function() {
return this._paused;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/paused:property"}}{{/crossLink}} directly as a property
* @method _setPaused
* @protected
* @param {boolean} value
* @since 0.6.0
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p._setPaused = function (value) {
if ((value !== true && value !== false) || this._paused == value) {return;}
if (value == true && this.playState != createjs.Sound.PLAY_SUCCEEDED) {return;}
this._paused = value;
if(value) {
this._pause();
} else {
this._resume();
}
clearTimeout(this.delayTimeoutId);
return this;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/volume:property"}}{{/crossLink}} directly as a property
* @method _setVolume
* @protected
* @param {Number} value The volume to set, between 0 and 1.
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
*/
p._setVolume = function (value) {
if (value == this._volume) { return this; }
this._volume = Math.max(0, Math.min(1, value));
if (!this._muted) {
this._updateVolume();
}
return this;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/volume:property"}}{{/crossLink}} directly as a property
* @method _getVolume
* @protected
* @return {Number} The current volume of the sound instance.
*/
p._getVolume = function () {
return this._volume;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/muted:property"}}{{/crossLink}} directly as a property
* @method _setMuted
* @protected
* @param {Boolean} value If the sound should be muted.
* @return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
* @since 0.6.0
*/
p._setMuted = function (value) {
if (value !== true && value !== false) {return;}
this._muted = value;
this._updateVolume();
return this;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/muted:property"}}{{/crossLink}} directly as a property
* @method _getMuted
* @protected
* @return {Boolean} If the sound is muted.
* @since 0.6.0
*/
p._getMuted = function () {
return this._muted;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/pan:property"}}{{/crossLink}} directly as a property
* @method _setPan
* @protected
* @param {Number} value The pan value, between -1 (left) and 1 (right).
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p._setPan = function (value) {
if(value == this._pan) { return this; }
this._pan = Math.max(-1, Math.min(1, value));
this._updatePan();
return this;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/pan:property"}}{{/crossLink}} directly as a property
* @method _getPan
* @protected
* @return {Number} The value of the pan, between -1 (left) and 1 (right).
*/
p._getPan = function () {
return this._pan;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/position:property"}}{{/crossLink}} directly as a property
* @method _getPosition
* @protected
* @return {Number} The position of the playhead in the sound, in milliseconds.
*/
p._getPosition = function () {
if (!this._paused && this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this._position = this._calculateCurrentPosition();
}
return this._position;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/position:property"}}{{/crossLink}} directly as a property
* @method _setPosition
* @protected
* @param {Number} value The position to place the playhead, in milliseconds.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p._setPosition = function (value) {
this._position = Math.max(0, value);
if (this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this._updatePosition();
}
return this;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
* @method _getStartTime
* @protected
* @return {Number} The startTime of the sound instance in milliseconds.
*/
p._getStartTime = function () {
return this._startTime;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
* @method _setStartTime
* @protected
* @param {number} value The new startTime time in milli seconds.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
*/
p._setStartTime = function (value) {
if (value == this._startTime) { return this; }
this._startTime = Math.max(0, value || 0);
this._updateStartTime();
return this;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/duration:property"}}{{/crossLink}} directly as a property
* @method _getDuration
* @protected
* @return {Number} The duration of the sound instance in milliseconds.
*/
p._getDuration = function () {
return this._duration;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/duration:property"}}{{/crossLink}} directly as a property
* @method _setDuration
* @protected
* @param {number} value The new duration time in milli seconds.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
* @since 0.6.0
*/
p._setDuration = function (value) {
if (value == this._duration) { return this; }
this._duration = Math.max(0, value || 0);
this._updateDuration();
return this;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/playbackResource:property"}}{{/crossLink}} directly as a property
* @method _setPlaybackResource
* @protected
* @param {Object} value The new playback resource.
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
* @since 0.6.0
**/
p._setPlaybackResource = function (value) {
this._playbackResource = value;
if (this._duration == 0 && this._playbackResource) { this._setDurationFromSource(); }
return this;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/playbackResource:property"}}{{/crossLink}} directly as a property
* @method _getPlaybackResource
* @protected
* @param {Object} value The new playback resource.
* @return {Object} playback resource used for playing audio
* @since 0.6.0
**/
p._getPlaybackResource = function () {
return this._playbackResource;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/loop:property"}}{{/crossLink}} directly as a property
* @method _getLoop
* @protected
* @return {number}
* @since 0.6.0
**/
p._getLoop = function () {
return this._loop;
};
/**
* Please use {{#crossLink "AbstractSoundInstance/loop:property"}}{{/crossLink}} directly as a property
* @method _setLoop
* @protected
* @param {number} value The number of times to loop after play.
* @since 0.6.0
*/
p._setLoop = function (value) {
if(this._playbackResource != null) {
// remove looping
if (this._loop != 0 && value == 0) {
this._removeLooping(value);
}
// add looping
else if (this._loop == 0 && value != 0) {
this._addLooping(value);
}
}
this._loop = value;
};
// Private Methods:
/**
* A helper method that dispatches all events for AbstractSoundInstance.
* @method _sendEvent
* @param {String} type The event type
* @protected
*/
p._sendEvent = function (type) {
var event = new createjs.Event(type);
this.dispatchEvent(event);
};
/**
* Clean up the instance. Remove references and clean up any additional properties such as timers.
* @method _cleanUp
* @protected
*/
p._cleanUp = function () {
clearTimeout(this.delayTimeoutId); // clear timeout that plays delayed sound
this._handleCleanUp();
this._paused = false;
createjs.Sound._playFinished(this); // TODO change to an event
};
/**
* The sound has been interrupted.
* @method _interrupt
* @protected
*/
p._interrupt = function () {
this._cleanUp();
this.playState = createjs.Sound.PLAY_INTERRUPTED;
this._sendEvent("interrupted");
};
/**
* Called by the Sound class when the audio is ready to play (delay has completed). Starts sound playing if the
* src is loaded, otherwise playback will fail.
* @method _beginPlaying
* @param {PlayPropsConfig} playProps A PlayPropsConfig object.
* @return {Boolean} If playback succeeded.
* @protected
*/
// OJR FlashAudioSoundInstance overwrites
p._beginPlaying = function (playProps) {
this._setPosition(playProps.offset);
this._setLoop(playProps.loop);
this._setVolume(playProps.volume);
this._setPan(playProps.pan);
if (playProps.startTime != null) {
this._setStartTime(playProps.startTime);
this._setDuration(playProps.duration);
}
if (this._playbackResource != null && this._position < this._duration) {
this._paused = false;
this._handleSoundReady();
this.playState = createjs.Sound.PLAY_SUCCEEDED;
this._sendEvent("succeeded");
return true;
} else {
this._playFailed();
return false;
}
};
/**
* Play has failed, which can happen for a variety of reasons.
* Cleans up instance and dispatches failed event
* @method _playFailed
* @private
*/
p._playFailed = function () {
this._cleanUp();
this.playState = createjs.Sound.PLAY_FAILED;
this._sendEvent("failed");
};
/**
* Audio has finished playing. Manually loop it if required.
* @method _handleSoundComplete
* @param event
* @protected
*/
p._handleSoundComplete = function (event) {
this._position = 0; // have to set this as it can be set by pause during playback
if (this._loop != 0) {
this._loop--; // NOTE this introduces a theoretical limit on loops = float max size x 2 - 1
this._handleLoop();
this._sendEvent("loop");
return;
}
this._cleanUp();
this.playState = createjs.Sound.PLAY_FINISHED;
this._sendEvent("complete");
};
// Plugin specific code
/**
* Handles starting playback when the sound is ready for playing.
* @method _handleSoundReady
* @protected
*/
p._handleSoundReady = function () {
// plugin specific code
};
/**
* Internal function used to update the volume based on the instance volume, master volume, instance mute value,
* and master mute value.
* @method _updateVolume
* @protected
*/
p._updateVolume = function () {
// plugin specific code
};
/**
* Internal function used to update the pan
* @method _updatePan
* @protected
* @since 0.6.0
*/
p._updatePan = function () {
// plugin specific code
};
/**
* Internal function used to update the startTime of the audio.
* @method _updateStartTime
* @protected
* @since 0.6.1
*/
p._updateStartTime = function () {
// plugin specific code
};
/**
* Internal function used to update the duration of the audio.
* @method _updateDuration
* @protected
* @since 0.6.0
*/
p._updateDuration = function () {
// plugin specific code
};
/**
* Internal function used to get the duration of the audio from the source we'll be playing.
* @method _updateDuration
* @protected
* @since 0.6.0
*/
p._setDurationFromSource = function () {
// plugin specific code
};
/**
* Internal function that calculates the current position of the playhead and sets this._position to that value
* @method _calculateCurrentPosition
* @protected
* @since 0.6.0
*/
p._calculateCurrentPosition = function () {
// plugin specific code that sets this.position
};
/**
* Internal function used to update the position of the playhead.
* @method _updatePosition
* @protected
* @since 0.6.0
*/
p._updatePosition = function () {
// plugin specific code
};
/**
* Internal function called when looping is removed during playback.
* @method _removeLooping
* @param {number} value The number of times to loop after play.
* @protected
* @since 0.6.0
*/
p._removeLooping = function (value) {
// plugin specific code
};
/**
* Internal function called when looping is added during playback.
* @method _addLooping
* @param {number} value The number of times to loop after play.
* @protected
* @since 0.6.0
*/
p._addLooping = function (value) {
// plugin specific code
};
/**
* Internal function called when pausing playback
* @method _pause
* @protected
* @since 0.6.0
*/
p._pause = function () {
// plugin specific code
};
/**
* Internal function called when resuming playback
* @method _resume
* @protected
* @since 0.6.0
*/
p._resume = function () {
// plugin specific code
};
/**
* Internal function called when stopping playback
* @method _handleStop
* @protected
* @since 0.6.0
*/
p._handleStop = function() {
// plugin specific code
};
/**
* Internal function called when AbstractSoundInstance is being cleaned up
* @method _handleCleanUp
* @protected
* @since 0.6.0
*/
p._handleCleanUp = function() {
// plugin specific code
};
/**
* Internal function called when AbstractSoundInstance has played to end and is looping
* @method _handleLoop
* @protected
* @since 0.6.0
*/
p._handleLoop = function () {
// plugin specific code
};
createjs.AbstractSoundInstance = createjs.promote(AbstractSoundInstance, "EventDispatcher");
createjs.DefaultSoundInstance = createjs.AbstractSoundInstance; // used when no plugin is supported
}()); | A AbstractSoundInstance is created when any calls to the Sound API method {{#crossLink "Sound/play"}}{{/crossLink}} or
{{#crossLink "Sound/createInstance"}}{{/crossLink}} are made. The AbstractSoundInstance is returned by the active plugin
for control by the user.
<h4>Example</h4>
var myInstance = createjs.Sound.play("myAssetPath/mySrcFile.mp3");
A number of additional parameters provide a quick way to determine how a sound is played. Please see the Sound
API method {{#crossLink "Sound/play"}}{{/crossLink}} for a list of arguments.
Once a AbstractSoundInstance is created, a reference can be stored that can be used to control the audio directly through
the AbstractSoundInstance. If the reference is not stored, the AbstractSoundInstance will play out its audio (and any loops), and
is then de-referenced from the {{#crossLink "Sound"}}{{/crossLink}} class so that it can be cleaned up. If audio
playback has completed, a simple call to the {{#crossLink "AbstractSoundInstance/play"}}{{/crossLink}} instance method
will rebuild the references the Sound class need to control it.
var myInstance = createjs.Sound.play("myAssetPath/mySrcFile.mp3", {loop:2});
myInstance.on("loop", handleLoop);
function handleLoop(event) {
myInstance.volume = myInstance.volume * 0.5;
}
Events are dispatched from the instance to notify when the sound has completed, looped, or when playback fails
var myInstance = createjs.Sound.play("myAssetPath/mySrcFile.mp3");
myInstance.on("complete", handleComplete);
myInstance.on("loop", handleLoop);
myInstance.on("failed", handleFailed);
@class AbstractSoundInstance
@param {String} src The path to and file name of the sound.
@param {Number} startTime Audio sprite property used to apply an offset, in milliseconds.
@param {Number} duration Audio sprite property used to set the time the clip plays for, in milliseconds.
@param {Object} playbackResource Any resource needed by plugin to support audio playback.
@extends EventDispatcher
@constructor | (anonymous) ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
var AbstractPlugin = function () {
// private properties:
/**
* The capabilities of the plugin.
* method and is used internally.
* @property _capabilities
* @type {Object}
* @default null
* @protected
* @static
*/
this._capabilities = null;
/**
* Object hash indexed by the source URI of all created loaders, used to properly destroy them if sources are removed.
* @type {Object}
* @protected
*/
this._loaders = {};
/**
* Object hash indexed by the source URI of each file to indicate if an audio source has begun loading,
* is currently loading, or has completed loading. Can be used to store non boolean data after loading
* is complete (for example arrayBuffers for web audio).
* @property _audioSources
* @type {Object}
* @protected
*/
this._audioSources = {};
/**
* Object hash indexed by the source URI of all created SoundInstances, updates the playbackResource if it loads after they are created,
* and properly destroy them if sources are removed
* @type {Object}
* @protected
*/
this._soundInstances = {};
/**
* The internal master volume value of the plugin.
* @property _volume
* @type {Number}
* @default 1
* @protected
*/
this._volume = 1;
/**
* A reference to a loader class used by a plugin that must be set.
* @type {Object}
* @protected
*/
this._loaderClass;
/**
* A reference to an AbstractSoundInstance class used by a plugin that must be set.
* @type {Object}
* @protected;
*/
this._soundInstanceClass;
}; | A default plugin class used as a base for all other plugins.
@class AbstractPlugin
@constructor
@since 0.6.0 | AbstractPlugin ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
AbstractPlugin.isSupported = function () {
return true;
}; | Determine if the plugin can be used in the current browser/OS.
@method isSupported
@return {Boolean} If the plugin can be initialized.
@static | AbstractPlugin.isSupported ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.register = function (loadItem) {
var loader = this._loaders[loadItem.src];
if(loader && !loader.canceled) {return this._loaders[loadItem.src];} // already loading/loaded this, so don't load twice
// OJR potential issue that we won't be firing loaded event, might need to trigger if this is already loaded?
this._audioSources[loadItem.src] = true;
this._soundInstances[loadItem.src] = [];
loader = new this._loaderClass(loadItem);
loader.on("complete", this._handlePreloadComplete, this);
this._loaders[loadItem.src] = loader;
return loader;
}; | Pre-register a sound for preloading and setup. This is called by {{#crossLink "Sound"}}{{/crossLink}}.
Note all plugins provide a <code>Loader</code> instance, which <a href="http://preloadjs.com" target="_blank">PreloadJS</a>
can use to assist with preloading.
@method register
@param {String} loadItem An Object containing the source of the audio
Note that not every plugin will manage this value.
@return {Object} A result object, containing a "tag" for preloading purposes. | p.register ( loadItem ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.preload = function (loader) {
loader.on("error", this._handlePreloadError, this);
loader.load();
}; | Internally preload a sound.
@method preload
@param {Loader} loader The sound URI to load. | p.preload ( loader ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.isPreloadStarted = function (src) {
return (this._audioSources[src] != null);
}; | Checks if preloading has started for a specific source. If the source is found, we can assume it is loading,
or has already finished loading.
@method isPreloadStarted
@param {String} src The sound URI to check.
@return {Boolean} | p.isPreloadStarted ( src ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.isPreloadComplete = function (src) {
return (!(this._audioSources[src] == null || this._audioSources[src] == true));
}; | Checks if preloading has finished for a specific source.
@method isPreloadComplete
@param {String} src The sound URI to load.
@return {Boolean} | p.isPreloadComplete ( src ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.removeSound = function (src) {
if (!this._soundInstances[src]) { return; }
for (var i = this._soundInstances[src].length; i--; ) {
var item = this._soundInstances[src][i];
item.destroy();
}
delete(this._soundInstances[src]);
delete(this._audioSources[src]);
if(this._loaders[src]) { this._loaders[src].destroy(); }
delete(this._loaders[src]);
}; | Remove a sound added using {{#crossLink "WebAudioPlugin/register"}}{{/crossLink}}. Note this does not cancel a preload.
@method removeSound
@param {String} src The sound URI to unload. | p.removeSound ( src ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.removeAllSounds = function () {
for(var key in this._audioSources) {
this.removeSound(key);
}
}; | Remove all sounds added using {{#crossLink "WebAudioPlugin/register"}}{{/crossLink}}. Note this does not cancel a preload.
@method removeAllSounds
@param {String} src The sound URI to unload. | p.removeAllSounds ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.create = function (src, startTime, duration) {
if (!this.isPreloadStarted(src)) {
this.preload(this.register(src));
}
var si = new this._soundInstanceClass(src, startTime, duration, this._audioSources[src]);
if(this._soundInstances[src]){
this._soundInstances[src].push(si);
}
// Plugins that don't have a setVolume should implement a setMasterVolune/setMasterMute
// So we have to check that here.
si.setMasterVolume && si.setMasterVolume(createjs.Sound.volume);
si.setMasterMute && si.setMasterMute(createjs.Sound.muted);
return si;
}; | Create a sound instance. If the sound has not been preloaded, it is internally preloaded here.
@method create
@param {String} src The sound source to use.
@param {Number} startTime Audio sprite property used to apply an offset, in milliseconds.
@param {Number} duration Audio sprite property used to set the time the clip plays for, in milliseconds.
@return {AbstractSoundInstance} A sound instance for playback and control. | p.create ( src , startTime , duration ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.setVolume = function (value) {
this._volume = value;
this._updateVolume();
return true;
}; | Set the master volume of the plugin, which affects all SoundInstances.
@method setVolume
@param {Number} value The volume to set, between 0 and 1.
@return {Boolean} If the plugin processes the setVolume call (true). The Sound class will affect all the
instances manually otherwise. | p.setVolume ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.getVolume = function () {
return this._volume;
}; | Get the master volume of the plugin, which affects all SoundInstances.
@method getVolume
@return {Number} The volume level, between 0 and 1. | p.getVolume ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.setMute = function (value) {
this._updateVolume();
return true;
}; | Mute all sounds via the plugin.
@method setMute
@param {Boolean} value If all sound should be muted or not. Note that plugin-level muting just looks up
the mute value of Sound {{#crossLink "Sound/muted:property"}}{{/crossLink}}, so this property is not used here.
@return {Boolean} If the mute call succeeds. | p.setMute ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handlePreloadComplete = function (event) {
var src = event.target.getItem().src;
this._audioSources[src] = event.result;
for (var i = 0, l = this._soundInstances[src].length; i < l; i++) {
var item = this._soundInstances[src][i];
item.playbackResource = this._audioSources[src];
// ToDo consider adding play call here if playstate == playfailed
this._soundInstances[src] = null;
}
}; | Handles internal preload completion.
@method _handlePreloadComplete
@param event
@protected | p._handlePreloadComplete ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handlePreloadError = function(event) {
//delete(this._audioSources[src]);
}; | Handles internal preload errors
@method _handlePreloadError
@param event
@protected | p._handlePreloadError ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._updateVolume = function () {
// Plugin Specific code
}; | Set the gain value for master audio. Should not be called externally.
@method _updateVolume
@protected | p._updateVolume ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function Loader(loadItem) {
this.AbstractLoader_constructor(loadItem, true, createjs.Types.SOUND);
}; | Loader provides a mechanism to preload Web Audio content via PreloadJS or internally. Instances are returned to
the preloader, and the load method is called when the asset needs to be requested.
@class WebAudioLoader
@param {String} loadItem The item to be loaded
@extends XHRRequest
@protected | Loader ( loadItem ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleAudioDecoded = function (decodedAudio) {
this._result = decodedAudio;
this.AbstractLoader__sendComplete();
}; | The audio has been decoded.
@method handleAudioDecoded
@param decoded
@protected | p._handleAudioDecoded ( decodedAudio ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._cleanUpAudioNode = function(audioNode) {
if(audioNode) {
audioNode.stop(0);
audioNode.disconnect(0);
// necessary to prevent leak on iOS Safari 7-9. will throw in almost all other
// browser implementations.
if ( createjs.BrowserDetect.isIOS ) {
try { audioNode.buffer = s._scratchBuffer; } catch(e) {}
}
audioNode = null;
}
return audioNode;
}; | Turn off and disconnect an audioNode, then set reference to null to release it for garbage collection
@method _cleanUpAudioNode
@param audioNode
@return {audioNode}
@protected
@since 0.4.1 | p._cleanUpAudioNode ( audioNode ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._createAndPlayAudioNode = function(startTime, offset) {
var audioNode = s.context.createBufferSource();
audioNode.buffer = this.playbackResource;
audioNode.connect(this.panNode);
var dur = this._duration * 0.001;
audioNode.startTime = startTime + dur;
audioNode.start(audioNode.startTime, offset+(this._startTime*0.001), dur - offset);
return audioNode;
}; | Creates an audio node using the current src and context, connects it to the gain node, and starts playback.
@method _createAndPlayAudioNode
@param {Number} startTime The time to add this to the web audio context, in seconds.
@param {Number} offset The amount of time into the src audio to start playback, in seconds.
@return {audioNode}
@protected
@since 0.4.1 | p._createAndPlayAudioNode ( startTime , offset ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
(function () {
"use strict";
function WebAudioSoundInstance(src, startTime, duration, playbackResource) {
this.AbstractSoundInstance_constructor(src, startTime, duration, playbackResource);
// public properties
/**
* NOTE this is only intended for use by advanced users.
* <br />GainNode for controlling <code>WebAudioSoundInstance</code> volume. Connected to the {{#crossLink "WebAudioSoundInstance/destinationNode:property"}}{{/crossLink}}.
* @property gainNode
* @type {AudioGainNode}
* @since 0.4.0
*
*/
this.gainNode = s.context.createGain();
/**
* NOTE this is only intended for use by advanced users.
* <br />A panNode allowing left and right audio channel panning only. Connected to WebAudioSoundInstance {{#crossLink "WebAudioSoundInstance/gainNode:property"}}{{/crossLink}}.
* @property panNode
* @type {AudioPannerNode}
* @since 0.4.0
*/
this.panNode = s.context.createPanner();
this.panNode.panningModel = s._panningModel;
this.panNode.connect(this.gainNode);
this._updatePan();
/**
* NOTE this is only intended for use by advanced users.
* <br />sourceNode is the audio source. Connected to WebAudioSoundInstance {{#crossLink "WebAudioSoundInstance/panNode:property"}}{{/crossLink}}.
* @property sourceNode
* @type {AudioNode}
* @since 0.4.0
*
*/
this.sourceNode = null;
// private properties
/**
* Timeout that is created internally to handle sound playing to completion.
* Stored so we can remove it when stop, pause, or cleanup are called
* @property _soundCompleteTimeout
* @type {timeoutVariable}
* @default null
* @protected
* @since 0.4.0
*/
this._soundCompleteTimeout = null;
/**
* NOTE this is only intended for use by very advanced users.
* _sourceNodeNext is the audio source for the next loop, inserted in a look ahead approach to allow for smooth
* looping. Connected to {{#crossLink "WebAudioSoundInstance/gainNode:property"}}{{/crossLink}}.
* @property _sourceNodeNext
* @type {AudioNode}
* @default null
* @protected
* @since 0.4.1
*
*/
this._sourceNodeNext = null;
/**
* Time audio started playback, in seconds. Used to handle set position, get position, and resuming from paused.
* @property _playbackStartTime
* @type {Number}
* @default 0
* @protected
* @since 0.4.0
*/
this._playbackStartTime = 0;
// Proxies, make removing listeners easier.
this._endedHandler = createjs.proxy(this._handleSoundComplete, this);
};
var p = createjs.extend(WebAudioSoundInstance, createjs.AbstractSoundInstance);
var s = WebAudioSoundInstance;
/**
* Note this is only intended for use by advanced users.
* <br />Audio context used to create nodes. This is and needs to be the same context used by {{#crossLink "WebAudioPlugin"}}{{/crossLink}}.
* @property context
* @type {AudioContext}
* @static
* @since 0.6.0
*/
s.context = null;
/**
* Note this is only intended for use by advanced users.
* <br />The scratch buffer that will be assigned to the buffer property of a source node on close.
* This is and should be the same scratch buffer referenced by {{#crossLink "WebAudioPlugin"}}{{/crossLink}}.
* @property _scratchBuffer
* @type {AudioBufferSourceNode}
* @static
*/
s._scratchBuffer = null;
/**
* Note this is only intended for use by advanced users.
* <br /> Audio node from WebAudioPlugin that sequences to <code>context.destination</code>
* @property destinationNode
* @type {AudioNode}
* @static
* @since 0.6.0
*/
s.destinationNode = null;
/**
* Value to set panning model to equal power for WebAudioSoundInstance. Can be "equalpower" or 0 depending on browser implementation.
* @property _panningModel
* @type {Number / String}
* @protected
* @static
* @since 0.6.0
*/
s._panningModel = "equalpower";
// Public methods
p.destroy = function() {
this.AbstractSoundInstance_destroy();
this.panNode.disconnect(0);
this.panNode = null;
this.gainNode.disconnect(0);
this.gainNode = null;
};
p.toString = function () {
return "[WebAudioSoundInstance]";
};
// Private Methods
p._updatePan = function() {
this.panNode.setPosition(this._pan, 0, -0.5);
// z need to be -0.5 otherwise the sound only plays in left, right, or center
};
p._removeLooping = function(value) {
this._sourceNodeNext = this._cleanUpAudioNode(this._sourceNodeNext);
};
p._addLooping = function(value) {
if (this.playState != createjs.Sound.PLAY_SUCCEEDED) { return; }
this._sourceNodeNext = this._createAndPlayAudioNode(this._playbackStartTime, 0);
};
p._setDurationFromSource = function () {
this._duration = this.playbackResource.duration * 1000;
};
p._handleCleanUp = function () {
if (this.sourceNode && this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this.sourceNode = this._cleanUpAudioNode(this.sourceNode);
this._sourceNodeNext = this._cleanUpAudioNode(this._sourceNodeNext);
}
if (this.gainNode.numberOfOutputs != 0) {this.gainNode.disconnect(0);}
// OJR there appears to be a bug that this doesn't always work in webkit (Chrome and Safari). According to the documentation, this should work.
clearTimeout(this._soundCompleteTimeout);
this._playbackStartTime = 0; // This is used by _getPosition
};
/**
* Turn off and disconnect an audioNode, then set reference to null to release it for garbage collection
* @method _cleanUpAudioNode
* @param audioNode
* @return {audioNode}
* @protected
* @since 0.4.1
*/
p._cleanUpAudioNode = function(audioNode) {
if(audioNode) {
audioNode.stop(0);
audioNode.disconnect(0);
// necessary to prevent leak on iOS Safari 7-9. will throw in almost all other
// browser implementations.
if ( createjs.BrowserDetect.isIOS ) {
try { audioNode.buffer = s._scratchBuffer; } catch(e) {}
}
audioNode = null;
}
return audioNode;
};
p._handleSoundReady = function (event) {
this.gainNode.connect(s.destinationNode); // this line can cause a memory leak. Nodes need to be disconnected from the audioDestination or any sequence that leads to it.
var dur = this._duration * 0.001,
pos = Math.min(Math.max(0, this._position) * 0.001, dur);
this.sourceNode = this._createAndPlayAudioNode((s.context.currentTime - dur), pos);
this._playbackStartTime = this.sourceNode.startTime - pos;
this._soundCompleteTimeout = setTimeout(this._endedHandler, (dur - pos) * 1000);
if(this._loop != 0) {
this._sourceNodeNext = this._createAndPlayAudioNode(this._playbackStartTime, 0);
}
};
/**
* Creates an audio node using the current src and context, connects it to the gain node, and starts playback.
* @method _createAndPlayAudioNode
* @param {Number} startTime The time to add this to the web audio context, in seconds.
* @param {Number} offset The amount of time into the src audio to start playback, in seconds.
* @return {audioNode}
* @protected
* @since 0.4.1
*/
p._createAndPlayAudioNode = function(startTime, offset) {
var audioNode = s.context.createBufferSource();
audioNode.buffer = this.playbackResource;
audioNode.connect(this.panNode);
var dur = this._duration * 0.001;
audioNode.startTime = startTime + dur;
audioNode.start(audioNode.startTime, offset+(this._startTime*0.001), dur - offset);
return audioNode;
};
p._pause = function () {
this._position = (s.context.currentTime - this._playbackStartTime) * 1000; // * 1000 to give milliseconds, lets us restart at same point
this.sourceNode = this._cleanUpAudioNode(this.sourceNode);
this._sourceNodeNext = this._cleanUpAudioNode(this._sourceNodeNext);
if (this.gainNode.numberOfOutputs != 0) {this.gainNode.disconnect(0);}
clearTimeout(this._soundCompleteTimeout);
};
p._resume = function () {
this._handleSoundReady();
};
/*
p._handleStop = function () {
// web audio does not need to do anything extra
};
*/
p._updateVolume = function () {
var newVolume = this._muted ? 0 : this._volume;
if (newVolume != this.gainNode.gain.value) {
this.gainNode.gain.value = newVolume;
}
};
p._calculateCurrentPosition = function () {
return ((s.context.currentTime - this._playbackStartTime) * 1000); // pos in seconds * 1000 to give milliseconds
};
p._updatePosition = function () {
this.sourceNode = this._cleanUpAudioNode(this.sourceNode);
this._sourceNodeNext = this._cleanUpAudioNode(this._sourceNodeNext);
clearTimeout(this._soundCompleteTimeout);
if (!this._paused) {this._handleSoundReady();}
};
// OJR we are using a look ahead approach to ensure smooth looping.
// We add _sourceNodeNext to the audio context so that it starts playing even if this callback is delayed.
// This technique is described here: http://www.html5rocks.com/en/tutorials/audio/scheduling/
// NOTE the cost of this is that our audio loop may not always match the loop event timing precisely.
p._handleLoop = function () {
this._cleanUpAudioNode(this.sourceNode);
this.sourceNode = this._sourceNodeNext;
this._playbackStartTime = this.sourceNode.startTime;
this._sourceNodeNext = this._createAndPlayAudioNode(this._playbackStartTime, 0);
this._soundCompleteTimeout = setTimeout(this._endedHandler, this._duration);
};
p._updateDuration = function () {
if(this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this._pause();
this._resume();
}
};
createjs.WebAudioSoundInstance = createjs.promote(WebAudioSoundInstance, "AbstractSoundInstance");
}()); | WebAudioSoundInstance extends the base api of {{#crossLink "AbstractSoundInstance"}}{{/crossLink}} and is used by
{{#crossLink "WebAudioPlugin"}}{{/crossLink}}.
WebAudioSoundInstance exposes audioNodes for advanced users.
@param {String} src The path to and file name of the sound.
@param {Number} startTime Audio sprite property used to apply an offset, in milliseconds.
@param {Number} duration Audio sprite property used to set the time the clip plays for, in milliseconds.
@param {Object} playbackResource Any resource needed by plugin to support audio playback.
@class WebAudioSoundInstance
@extends AbstractSoundInstance
@constructor | (anonymous) ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.playEmptySound = function() {
if (s.context == null) {return;}
var source = s.context.createBufferSource();
source.buffer = s._scratchBuffer;
source.connect(s.context.destination);
source.start(0, 0, 0);
}; | Plays an empty sound in the web audio context. This is used to enable web audio on iOS devices, as they
require the first sound to be played inside of a user initiated event (touch/click). This is called when
{{#crossLink "WebAudioPlugin"}}{{/crossLink}} is initialized (by Sound {{#crossLink "Sound/initializeDefaultPlugins"}}{{/crossLink}}
for example).
<h4>Example</h4>
function handleTouch(event) {
createjs.WebAudioPlugin.playEmptySound();
}
@method playEmptySound
@static
@since 0.4.1 | s.playEmptySound ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s._isFileXHRSupported = function() {
// it's much easier to detect when something goes wrong, so let's start optimistically
var supported = true;
var xhr = new XMLHttpRequest();
try {
xhr.open("GET", "WebAudioPluginTest.fail", false); // loading non-existant file triggers 404 only if it could load (synchronous call)
} catch (error) {
// catch errors in cases where the onerror is passed by
supported = false;
return supported;
}
xhr.onerror = function() { supported = false; }; // cause irrelevant
// with security turned off, we can get empty success results, which is actually a failed read (status code 0?)
xhr.onload = function() { supported = this.status == 404 || (this.status == 200 || (this.status == 0 && this.response != "")); };
try {
xhr.send();
} catch (error) {
// catch errors in cases where the onerror is passed by
supported = false;
}
return supported;
}; | Determine if XHR is supported, which is necessary for web audio.
@method _isFileXHRSupported
@return {Boolean} If XHR is supported.
@since 0.4.2
@private
@static | s._isFileXHRSupported ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s._createAudioContext = function() {
// Slightly modified version of https://github.com/Jam3/ios-safe-audio-context
// Resolves issues with first-run contexts playing garbled on iOS.
var AudioCtor = (window.AudioContext || window.webkitAudioContext);
if (AudioCtor == null) { return null; }
var context = new AudioCtor();
// Check if hack is necessary. Only occurs in iOS6+ devices
// and only when you first boot the iPhone, or play a audio/video
// with a different sample rate
if (/(iPhone|iPad)/i.test(navigator.userAgent)
&& context.sampleRate !== s.DEFAULT_SAMPLE_RATE) {
var buffer = context.createBuffer(1, 1, s.DEFAULT_SAMPLE_RATE),
dummy = context.createBufferSource();
dummy.buffer = buffer;
dummy.connect(context.destination);
dummy.start(0);
dummy.disconnect();
context.close() // dispose old context
context = new AudioCtor();
}
return context;
} | Create an audio context for the sound.
This method handles both vendor prefixes (specifically webkit support), as well as a case on iOS where
audio played with a different sample rate may play garbled when first started. The default sample rate is
44,100, however it can be changed using the {{#crossLink "WebAudioPlugin/DEFAULT_SAMPLE_RATE:property"}}{{/crossLink}}.
@method _createAudioContext
@return {AudioContext | webkitAudioContext}
@private
@static
@since 1.0.0 | s._createAudioContext ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s._compatibilitySetUp = function() {
s._panningModel = "equalpower";
//assume that if one new call is supported, they all are
if (s.context.createGain) { return; }
// simple name change, functionality the same
s.context.createGain = s.context.createGainNode;
// source node, add to prototype
var audioNode = s.context.createBufferSource();
audioNode.__proto__.start = audioNode.__proto__.noteGrainOn; // note that noteGrainOn requires all 3 parameters
audioNode.__proto__.stop = audioNode.__proto__.noteOff;
// panningModel
s._panningModel = 0;
}; | Set up compatibility if only deprecated web audio calls are supported.
See http://www.w3.org/TR/webaudio/#DeprecationNotes
Needed so we can support new browsers that don't support deprecated calls (Firefox) as well as old browsers that
don't support new calls.
@method _compatibilitySetUp
@static
@private
@since 0.4.2 | s._compatibilitySetUp ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s._unlock = function() {
if (s._unlocked) { return; }
s.playEmptySound();
if (s.context.state == "running") {
document.removeEventListener("mousedown", s._unlock, true);
document.removeEventListener("touchend", s._unlock, true);
document.removeEventListener("touchstart", s._unlock, true);
s._unlocked = true;
}
}; | Try to unlock audio on iOS. This is triggered from either WebAudio plugin setup (which will work if inside of
a `mousedown` or `touchend` event stack), or the first document touchend/mousedown event. If it fails (touchend
will fail if the user presses for too long, indicating a scroll event instead of a click event.
Note that earlier versions of iOS supported `touchstart` for this, but iOS9 removed this functionality. Adding
a `touchstart` event to support older platforms may preclude a `mousedown` even from getting fired on iOS9, so we
stick with `mousedown` and `touchend`.
@method _unlock
@since 0.6.2
@private | s._unlock ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._addPropsToClasses = function() {
var c = this._soundInstanceClass;
c.context = this.context;
c._scratchBuffer = s._scratchBuffer;
c.destinationNode = this.gainNode;
c._panningModel = this._panningModel;
this._loaderClass.context = this.context;
}; | Set up needed properties on supported classes WebAudioSoundInstance and WebAudioLoader.
@method _addPropsToClasses
@static
@protected
@since 0.6.0 | p._addPropsToClasses ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function HTMLAudioTagPool() {
throw "HTMLAudioTagPool cannot be instantiated";
} | HTMLAudioTagPool is an object pool for HTMLAudio tag instances.
@class HTMLAudioTagPool
@param {String} src The source of the channel.
@protected | HTMLAudioTagPool ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.get = function (src) {
var t = s._tags[src];
if (t == null) {
// create new base tag
t = s._tags[src] = s._tagPool.get();
t.src = src;
} else {
// get base or pool
if (s._tagUsed[src]) {
t = s._tagPool.get();
t.src = src;
} else {
s._tagUsed[src] = true;
}
}
return t;
}; | Get an audio tag with the given source.
@method get
@param {String} src The source file used by the audio tag.
@static | s.get ( src ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.set = function (src, tag) {
// check if this is base, if yes set boolean if not return to pool
if(tag == s._tags[src]) {
s._tagUsed[src] = false;
} else {
s._tagPool.set(tag);
}
}; | Return an audio tag to the pool.
@method set
@param {String} src The source file used by the audio tag.
@param {HTMLElement} tag Audio tag to set.
@static | s.set ( src , tag ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.remove = function (src) {
var tag = s._tags[src];
if (tag == null) {return false;}
s._tagPool.set(tag);
delete(s._tags[src]);
delete(s._tagUsed[src]);
return true;
}; | Delete stored tag reference and return them to pool. Note that if the tag reference does not exist, this will fail.
@method remove
@param {String} src The source for the tag
@return {Boolean} If the TagPool was deleted.
@static | s.remove ( src ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.getDuration= function (src) {
var t = s._tags[src];
if (t == null || !t.duration) {return 0;} // OJR duration is NaN if loading has not completed
return t.duration * 1000;
}; | Gets the duration of the src audio in milliseconds
@method getDuration
@param {String} src The source file used by the audio tag.
@return {Number} Duration of src in milliseconds
@static | s.getDuration ( src ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function TagPool(src) {
// Public Properties
/**
* A list of all available tags in the pool.
* #property tags
* @type {Array}
* @protected
*/
this._tags = [];
}; | The TagPool is an object pool for HTMLAudio tag instances.
#class TagPool
@param {String} src The source of the channel.
@protected | TagPool ( src ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.get = function () {
var tag;
if (this._tags.length == 0) {
tag = this._createTag();
} else {
tag = this._tags.pop();
}
if (tag.parentNode == null) {document.body.appendChild(tag);}
return tag;
}; | Get an HTMLAudioElement for immediate playback. This takes it out of the pool.
#method get
@return {HTMLAudioElement} An HTML audio tag. | p.get ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.set = function (tag) {
// OJR this first step seems unnecessary
var index = createjs.indexOf(this._tags, tag);
if (index == -1) {
this._tags.src = null;
this._tags.push(tag);
}
}; | Put an HTMLAudioElement back in the pool for use.
#method set
@param {HTMLAudioElement} tag HTML audio tag | p.set ( tag ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._createTag = function () {
var tag = document.createElement("audio");
tag.autoplay = false;
tag.preload = "none";
//LM: Firefox fails when this the preload="none" for other tags, but it needs to be "none" to ensure PreloadJS works.
return tag;
}; | Create an HTML audio tag.
#method _createTag
@param {String} src The source file to set for the audio tag.
@return {HTMLElement} Returns an HTML audio tag.
@protected | p._createTag ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function HTMLAudioSoundInstance(src, startTime, duration, playbackResource) {
this.AbstractSoundInstance_constructor(src, startTime, duration, playbackResource);
// Private Properties
this._audioSpriteStopTime = null;
this._delayTimeoutId = null;
// Proxies, make removing listeners easier.
this._endedHandler = createjs.proxy(this._handleSoundComplete, this);
this._readyHandler = createjs.proxy(this._handleTagReady, this);
this._stalledHandler = createjs.proxy(this._playFailed, this);
this._audioSpriteEndHandler = createjs.proxy(this._handleAudioSpriteLoop, this);
this._loopHandler = createjs.proxy(this._handleSoundComplete, this);
if (duration) {
this._audioSpriteStopTime = (startTime + duration) * 0.001;
} else {
this._duration = createjs.HTMLAudioTagPool.getDuration(this.src);
}
} | HTMLAudioSoundInstance extends the base api of {{#crossLink "AbstractSoundInstance"}}{{/crossLink}} and is used by
{{#crossLink "HTMLAudioPlugin"}}{{/crossLink}}.
@param {String} src The path to and file name of the sound.
@param {Number} startTime Audio sprite property used to apply an offset, in milliseconds.
@param {Number} duration Audio sprite property used to set the time the clip plays for, in milliseconds.
@param {Object} playbackResource Any resource needed by plugin to support audio playback.
@class HTMLAudioSoundInstance
@extends AbstractSoundInstance
@constructor | HTMLAudioSoundInstance ( src , startTime , duration , playbackResource ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleTagReady = function (event) {
this._playbackResource.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_READY, this._readyHandler, false);
this._playbackResource.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_STALLED, this._stalledHandler, false);
this._handleSoundReady();
}; | Used to handle when a tag is not ready for immediate playback when it is returned from the HTMLAudioTagPool.
@method _handleTagReady
@param event
@protected | p._handleTagReady ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleSetPositionSeek = function(event) {
if (this._playbackResource == null) { return; }
this._playbackResource.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_SEEKED, this._handleSetPositionSeek, false);
this._playbackResource.addEventListener(createjs.HTMLAudioPlugin._AUDIO_SEEKED, this._loopHandler, false);
}; | Used to enable setting position, as we need to wait for that seek to be done before we add back our loop handling seek listener
@method _handleSetPositionSeek
@param event
@protected | p._handleSetPositionSeek ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleAudioSpriteLoop = function (event) {
if(this._playbackResource.currentTime <= this._audioSpriteStopTime) {return;}
this._playbackResource.pause();
if(this._loop == 0) {
this._handleSoundComplete(null);
} else {
this._position = 0;
this._loop--;
this._playbackResource.currentTime = this._startTime * 0.001;
if(!this._paused) {this._playbackResource.play();}
this._sendEvent("loop");
}
}; | Timer used to loop audio sprites.
NOTE because of the inaccuracies in the timeupdate event (15 - 250ms) and in setting the tag to the desired timed
(up to 300ms), it is strongly recommended not to loop audio sprites with HTML Audio if smooth looping is desired
@method _handleAudioSpriteLoop
@param event
@private | p._handleAudioSpriteLoop ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function HTMLAudioPlugin() {
this.AbstractPlugin_constructor();
// Public Properties
this._capabilities = s._capabilities;
this._loaderClass = createjs.SoundLoader;
this._soundInstanceClass = createjs.HTMLAudioSoundInstance;
} | Play sounds using HTML <audio> tags in the browser. This plugin is the second priority plugin installed
by default, after the {{#crossLink "WebAudioPlugin"}}{{/crossLink}}. For older browsers that do not support html
audio, include and install the {{#crossLink "FlashAudioPlugin"}}{{/crossLink}}.
<h4>Known Browser and OS issues for HTML Audio</h4>
<b>All browsers</b><br />
Testing has shown in all browsers there is a limit to how many audio tag instances you are allowed. If you exceed
this limit, you can expect to see unpredictable results. Please use {{#crossLink "Sound.MAX_INSTANCES"}}{{/crossLink}} as
a guide to how many total audio tags you can safely use in all browsers. This issue is primarily limited to IE9.
<b>IE html limitations</b><br />
<ul><li>There is a delay in applying volume changes to tags that occurs once playback is started. So if you have
muted all sounds, they will all play during this delay until the mute applies internally. This happens regardless of
when or how you apply the volume change, as the tag seems to need to play to apply it.</li>
<li>MP3 encoding will not always work for audio tags if it's not default. We've found default encoding with
64kbps works.</li>
<li>Occasionally very short samples will get cut off.</li>
<li>There is a limit to how many audio tags you can load or play at once, which appears to be determined by
hardware and browser settings. See {{#crossLink "HTMLAudioPlugin.MAX_INSTANCES"}}{{/crossLink}} for a safe estimate.
Note that audio sprites can be used as a solution to this issue.</li></ul>
<b>Safari limitations</b><br />
<ul><li>Safari requires Quicktime to be installed for audio playback.</li></ul>
<b>iOS 6 limitations</b><br />
<ul><li>can only have one <audio> tag</li>
<li>can not preload or autoplay the audio</li>
<li>can not cache the audio</li>
<li>can not play the audio except inside a user initiated event.</li>
<li>Note it is recommended to use {{#crossLink "WebAudioPlugin"}}{{/crossLink}} for iOS (6+)</li>
<li>audio sprites can be used to mitigate some of these issues and are strongly recommended on iOS</li>
</ul>
<b>Android Native Browser limitations</b><br />
<ul><li>We have no control over audio volume. Only the user can set volume on their device.</li>
<li>We can only play audio inside a user event (touch/click). This currently means you cannot loop sound or use a delay.</li></ul>
<b> Android Chrome 26.0.1410.58 specific limitations</b><br />
<ul> <li>Can only play 1 sound at a time.</li>
<li>Sound is not cached.</li>
<li>Sound can only be loaded in a user initiated touch/click event.</li>
<li>There is a delay before a sound is played, presumably while the src is loaded.</li>
</ul>
See {{#crossLink "Sound"}}{{/crossLink}} for general notes on known issues.
@class HTMLAudioPlugin
@extends AbstractPlugin
@constructor | HTMLAudioPlugin ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
(function() {
if (document.body) { setupEmbed(); }
else { document.addEventListener("DOMContentLoaded", setupEmbed); }
function setupEmbed() {
if (window.top != window) {
document.body.className += " embedded";
}
}
var o = window.examples = {};
o.showDistractor = function(id) {
var div = id ? document.getElementById(id) : document.querySelector("div canvas").parentNode;
div.className += " loading";
};
o.hideDistractor = function() {
var div = document.querySelector(".loading");
div.className = div.className.replace(/\bloading\b/);
};
})(); | Very minimal shared code for examples. | (anonymous) ( ) | javascript | CreateJS/SoundJS | _assets/js/examples.js | https://github.com/CreateJS/SoundJS/blob/master/_assets/js/examples.js | MIT |
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('K M;I(M)1S 2U("2a\'t 4k M 4K 2g 3l 4G 4H");(6(){6 r(f,e){I(!M.1R(f))1S 3m("3s 15 4R");K a=f.1w;f=M(f.1m,t(f)+(e||""));I(a)f.1w={1m:a.1m,19:a.19?a.19.1a(0):N};H f}6 t(f){H(f.1J?"g":"")+(f.4s?"i":"")+(f.4p?"m":"")+(f.4v?"x":"")+(f.3n?"y":"")}6 B(f,e,a,b){K c=u.L,d,h,g;v=R;5K{O(;c--;){g=u[c];I(a&g.3r&&(!g.2p||g.2p.W(b))){g.2q.12=e;I((h=g.2q.X(f))&&h.P===e){d={3k:g.2b.W(b,h,a),1C:h};1N}}}}5v(i){1S i}5q{v=11}H d}6 p(f,e,a){I(3b.Z.1i)H f.1i(e,a);O(a=a||0;a<f.L;a++)I(f[a]===e)H a;H-1}M=6(f,e){K a=[],b=M.1B,c=0,d,h;I(M.1R(f)){I(e!==1d)1S 3m("2a\'t 5r 5I 5F 5B 5C 15 5E 5p");H r(f)}I(v)1S 2U("2a\'t W 3l M 59 5m 5g 5x 5i");e=e||"";O(d={2N:11,19:[],2K:6(g){H e.1i(g)>-1},3d:6(g){e+=g}};c<f.L;)I(h=B(f,c,b,d)){a.U(h.3k);c+=h.1C[0].L||1}Y I(h=n.X.W(z[b],f.1a(c))){a.U(h[0]);c+=h[0].L}Y{h=f.3a(c);I(h==="[")b=M.2I;Y I(h==="]")b=M.1B;a.U(h);c++}a=15(a.1K(""),n.Q.W(e,w,""));a.1w={1m:f,19:d.2N?d.19:N};H a};M.3v="1.5.0";M.2I=1;M.1B=2;K C=/\\$(?:(\\d\\d?|[$&`\'])|{([$\\w]+)})/g,w=/[^5h]+|([\\s\\S])(?=[\\s\\S]*\\1)/g,A=/^(?:[?*+]|{\\d+(?:,\\d*)?})\\??/,v=11,u=[],n={X:15.Z.X,1A:15.Z.1A,1C:1r.Z.1C,Q:1r.Z.Q,1e:1r.Z.1e},x=n.X.W(/()??/,"")[1]===1d,D=6(){K f=/^/g;n.1A.W(f,"");H!f.12}(),y=6(){K f=/x/g;n.Q.W("x",f,"");H!f.12}(),E=15.Z.3n!==1d,z={};z[M.2I]=/^(?:\\\\(?:[0-3][0-7]{0,2}|[4-7][0-7]?|x[\\29-26-f]{2}|u[\\29-26-f]{4}|c[A-3o-z]|[\\s\\S]))/;z[M.1B]=/^(?:\\\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9]\\d*|x[\\29-26-f]{2}|u[\\29-26-f]{4}|c[A-3o-z]|[\\s\\S])|\\(\\?[:=!]|[?*+]\\?|{\\d+(?:,\\d*)?}\\??)/;M.1h=6(f,e,a,b){u.U({2q:r(f,"g"+(E?"y":"")),2b:e,3r:a||M.1B,2p:b||N})};M.2n=6(f,e){K a=f+"/"+(e||"");H M.2n[a]||(M.2n[a]=M(f,e))};M.3c=6(f){H r(f,"g")};M.5l=6(f){H f.Q(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g,"\\\\$&")};M.5e=6(f,e,a,b){e=r(e,"g"+(b&&E?"y":""));e.12=a=a||0;f=e.X(f);H b?f&&f.P===a?f:N:f};M.3q=6(){M.1h=6(){1S 2U("2a\'t 55 1h 54 3q")}};M.1R=6(f){H 53.Z.1q.W(f)==="[2m 15]"};M.3p=6(f,e,a,b){O(K c=r(e,"g"),d=-1,h;h=c.X(f);){a.W(b,h,++d,f,c);c.12===h.P&&c.12++}I(e.1J)e.12=0};M.57=6(f,e){H 6 a(b,c){K d=e[c].1I?e[c]:{1I:e[c]},h=r(d.1I,"g"),g=[],i;O(i=0;i<b.L;i++)M.3p(b[i],h,6(k){g.U(d.3j?k[d.3j]||"":k[0])});H c===e.L-1||!g.L?g:a(g,c+1)}([f],0)};15.Z.1p=6(f,e){H J.X(e[0])};15.Z.W=6(f,e){H J.X(e)};15.Z.X=6(f){K e=n.X.1p(J,14),a;I(e){I(!x&&e.L>1&&p(e,"")>-1){a=15(J.1m,n.Q.W(t(J),"g",""));n.Q.W(f.1a(e.P),a,6(){O(K c=1;c<14.L-2;c++)I(14[c]===1d)e[c]=1d})}I(J.1w&&J.1w.19)O(K b=1;b<e.L;b++)I(a=J.1w.19[b-1])e[a]=e[b];!D&&J.1J&&!e[0].L&&J.12>e.P&&J.12--}H e};I(!D)15.Z.1A=6(f){(f=n.X.W(J,f))&&J.1J&&!f[0].L&&J.12>f.P&&J.12--;H!!f};1r.Z.1C=6(f){M.1R(f)||(f=15(f));I(f.1J){K e=n.1C.1p(J,14);f.12=0;H e}H f.X(J)};1r.Z.Q=6(f,e){K a=M.1R(f),b,c;I(a&&1j e.58()==="3f"&&e.1i("${")===-1&&y)H n.Q.1p(J,14);I(a){I(f.1w)b=f.1w.19}Y f+="";I(1j e==="6")c=n.Q.W(J,f,6(){I(b){14[0]=1f 1r(14[0]);O(K d=0;d<b.L;d++)I(b[d])14[0][b[d]]=14[d+1]}I(a&&f.1J)f.12=14[14.L-2]+14[0].L;H e.1p(N,14)});Y{c=J+"";c=n.Q.W(c,f,6(){K d=14;H n.Q.W(e,C,6(h,g,i){I(g)5b(g){24"$":H"$";24"&":H d[0];24"`":H d[d.L-1].1a(0,d[d.L-2]);24"\'":H d[d.L-1].1a(d[d.L-2]+d[0].L);5a:i="";g=+g;I(!g)H h;O(;g>d.L-3;){i=1r.Z.1a.W(g,-1)+i;g=1Q.3i(g/10)}H(g?d[g]||"":"$")+i}Y{g=+i;I(g<=d.L-3)H d[g];g=b?p(b,i):-1;H g>-1?d[g+1]:h}})})}I(a&&f.1J)f.12=0;H c};1r.Z.1e=6(f,e){I(!M.1R(f))H n.1e.1p(J,14);K a=J+"",b=[],c=0,d,h;I(e===1d||+e<0)e=5D;Y{e=1Q.3i(+e);I(!e)H[]}O(f=M.3c(f);d=f.X(a);){I(f.12>c){b.U(a.1a(c,d.P));d.L>1&&d.P<a.L&&3b.Z.U.1p(b,d.1a(1));h=d[0].L;c=f.12;I(b.L>=e)1N}f.12===d.P&&f.12++}I(c===a.L){I(!n.1A.W(f,"")||h)b.U("")}Y b.U(a.1a(c));H b.L>e?b.1a(0,e):b};M.1h(/\\(\\?#[^)]*\\)/,6(f){H n.1A.W(A,f.2S.1a(f.P+f[0].L))?"":"(?:)"});M.1h(/\\((?!\\?)/,6(){J.19.U(N);H"("});M.1h(/\\(\\?<([$\\w]+)>/,6(f){J.19.U(f[1]);J.2N=R;H"("});M.1h(/\\\\k<([\\w$]+)>/,6(f){K e=p(J.19,f[1]);H e>-1?"\\\\"+(e+1)+(3R(f.2S.3a(f.P+f[0].L))?"":"(?:)"):f[0]});M.1h(/\\[\\^?]/,6(f){H f[0]==="[]"?"\\\\b\\\\B":"[\\\\s\\\\S]"});M.1h(/^\\(\\?([5A]+)\\)/,6(f){J.3d(f[1]);H""});M.1h(/(?:\\s+|#.*)+/,6(f){H n.1A.W(A,f.2S.1a(f.P+f[0].L))?"":"(?:)"},M.1B,6(){H J.2K("x")});M.1h(/\\./,6(){H"[\\\\s\\\\S]"},M.1B,6(){H J.2K("s")})})();1j 2e!="1d"&&(2e.M=M);K 1v=6(){6 r(a,b){a.1l.1i(b)!=-1||(a.1l+=" "+b)}6 t(a){H a.1i("3e")==0?a:"3e"+a}6 B(a){H e.1Y.2A[t(a)]}6 p(a,b,c){I(a==N)H N;K d=c!=R?a.3G:[a.2G],h={"#":"1c",".":"1l"}[b.1o(0,1)]||"3h",g,i;g=h!="3h"?b.1o(1):b.5u();I((a[h]||"").1i(g)!=-1)H a;O(a=0;d&&a<d.L&&i==N;a++)i=p(d[a],b,c);H i}6 C(a,b){K c={},d;O(d 2g a)c[d]=a[d];O(d 2g b)c[d]=b[d];H c}6 w(a,b,c,d){6 h(g){g=g||1P.5y;I(!g.1F){g.1F=g.52;g.3N=6(){J.5w=11}}c.W(d||1P,g)}a.3g?a.3g("4U"+b,h):a.4y(b,h,11)}6 A(a,b){K c=e.1Y.2j,d=N;I(c==N){c={};O(K h 2g e.1U){K g=e.1U[h];d=g.4x;I(d!=N){g.1V=h.4w();O(g=0;g<d.L;g++)c[d[g]]=h}}e.1Y.2j=c}d=e.1U[c[a]];d==N&&b!=11&&1P.1X(e.13.1x.1X+(e.13.1x.3E+a));H d}6 v(a,b){O(K c=a.1e("\\n"),d=0;d<c.L;d++)c[d]=b(c[d],d);H c.1K("\\n")}6 u(a,b){I(a==N||a.L==0||a=="\\n")H a;a=a.Q(/</g,"&1y;");a=a.Q(/ {2,}/g,6(c){O(K d="",h=0;h<c.L-1;h++)d+=e.13.1W;H d+" "});I(b!=N)a=v(a,6(c){I(c.L==0)H"";K d="";c=c.Q(/^(&2s;| )+/,6(h){d=h;H""});I(c.L==0)H d;H d+\'<17 1g="\'+b+\'">\'+c+"</17>"});H a}6 n(a,b){a.1e("\\n");O(K c="",d=0;d<50;d++)c+=" ";H a=v(a,6(h){I(h.1i("\\t")==-1)H h;O(K g=0;(g=h.1i("\\t"))!=-1;)h=h.1o(0,g)+c.1o(0,b-g%b)+h.1o(g+1,h.L);H h})}6 x(a){H a.Q(/^\\s+|\\s+$/g,"")}6 D(a,b){I(a.P<b.P)H-1;Y I(a.P>b.P)H 1;Y I(a.L<b.L)H-1;Y I(a.L>b.L)H 1;H 0}6 y(a,b){6 c(k){H k[0]}O(K d=N,h=[],g=b.2D?b.2D:c;(d=b.1I.X(a))!=N;){K i=g(d,b);I(1j i=="3f")i=[1f e.2L(i,d.P,b.23)];h=h.1O(i)}H h}6 E(a){K b=/(.*)((&1G;|&1y;).*)/;H a.Q(e.3A.3M,6(c){K d="",h=N;I(h=b.X(c)){c=h[1];d=h[2]}H\'<a 2h="\'+c+\'">\'+c+"</a>"+d})}6 z(){O(K a=1E.36("1k"),b=[],c=0;c<a.L;c++)a[c].3s=="20"&&b.U(a[c]);H b}6 f(a){a=a.1F;K b=p(a,".20",R);a=p(a,".3O",R);K c=1E.4i("3t");I(!(!a||!b||p(a,"3t"))){B(b.1c);r(b,"1m");O(K d=a.3G,h=[],g=0;g<d.L;g++)h.U(d[g].4z||d[g].4A);h=h.1K("\\r");c.39(1E.4D(h));a.39(c);c.2C();c.4C();w(c,"4u",6(){c.2G.4E(c);b.1l=b.1l.Q("1m","")})}}I(1j 3F!="1d"&&1j M=="1d")M=3F("M").M;K e={2v:{"1g-27":"","2i-1s":1,"2z-1s-2t":11,1M:N,1t:N,"42-45":R,"43-22":4,1u:R,16:R,"3V-17":R,2l:11,"41-40":R,2k:11,"1z-1k":11},13:{1W:"&2s;",2M:R,46:11,44:11,34:"4n",1x:{21:"4o 1m",2P:"?",1X:"1v\\n\\n",3E:"4r\'t 4t 1D O: ",4g:"4m 4B\'t 51 O 1z-1k 4F: ",37:\'<!4T 1z 4S "-//4V//3H 4W 1.0 4Z//4Y" "1Z://2y.3L.3K/4X/3I/3H/3I-4P.4J"><1z 4I="1Z://2y.3L.3K/4L/5L"><3J><4N 1Z-4M="5G-5M" 6K="2O/1z; 6J=6I-8" /><1t>6L 1v</1t></3J><3B 1L="25-6M:6Q,6P,6O,6N-6F;6y-2f:#6x;2f:#6w;25-22:6v;2O-3D:3C;"><T 1L="2O-3D:3C;3w-32:1.6z;"><T 1L="25-22:6A-6E;">1v</T><T 1L="25-22:.6C;3w-6B:6R;"><T>3v 3.0.76 (72 73 3x)</T><T><a 2h="1Z://3u.2w/1v" 1F="38" 1L="2f:#3y">1Z://3u.2w/1v</a></T><T>70 17 6U 71.</T><T>6T 6X-3x 6Y 6D.</T></T><T>6t 61 60 J 1k, 5Z <a 2h="6u://2y.62.2w/63-66/65?64=5X-5W&5P=5O" 1L="2f:#3y">5R</a> 5V <2R/>5U 5T 5S!</T></T></3B></1z>\'}},1Y:{2j:N,2A:{}},1U:{},3A:{6n:/\\/\\*[\\s\\S]*?\\*\\//2c,6m:/\\/\\/.*$/2c,6l:/#.*$/2c,6k:/"([^\\\\"\\n]|\\\\.)*"/g,6o:/\'([^\\\\\'\\n]|\\\\.)*\'/g,6p:1f M(\'"([^\\\\\\\\"]|\\\\\\\\.)*"\',"3z"),6s:1f M("\'([^\\\\\\\\\']|\\\\\\\\.)*\'","3z"),6q:/(&1y;|<)!--[\\s\\S]*?--(&1G;|>)/2c,3M:/\\w+:\\/\\/[\\w-.\\/?%&=:@;]*/g,6a:{18:/(&1y;|<)\\?=?/g,1b:/\\?(&1G;|>)/g},69:{18:/(&1y;|<)%=?/g,1b:/%(&1G;|>)/g},6d:{18:/(&1y;|<)\\s*1k.*?(&1G;|>)/2T,1b:/(&1y;|<)\\/\\s*1k\\s*(&1G;|>)/2T}},16:{1H:6(a){6 b(i,k){H e.16.2o(i,k,e.13.1x[k])}O(K c=\'<T 1g="16">\',d=e.16.2x,h=d.2X,g=0;g<h.L;g++)c+=(d[h[g]].1H||b)(a,h[g]);c+="</T>";H c},2o:6(a,b,c){H\'<2W><a 2h="#" 1g="6e 6h\'+b+" "+b+\'">\'+c+"</a></2W>"},2b:6(a){K b=a.1F,c=b.1l||"";b=B(p(b,".20",R).1c);K d=6(h){H(h=15(h+"6f(\\\\w+)").X(c))?h[1]:N}("6g");b&&d&&e.16.2x[d].2B(b);a.3N()},2x:{2X:["21","2P"],21:{1H:6(a){I(a.V("2l")!=R)H"";K b=a.V("1t");H e.16.2o(a,"21",b?b:e.13.1x.21)},2B:6(a){a=1E.6j(t(a.1c));a.1l=a.1l.Q("47","")}},2P:{2B:6(){K a="68=0";a+=", 18="+(31.30-33)/2+", 32="+(31.2Z-2Y)/2+", 30=33, 2Z=2Y";a=a.Q(/^,/,"");a=1P.6Z("","38",a);a.2C();K b=a.1E;b.6W(e.13.1x.37);b.6V();a.2C()}}}},35:6(a,b){K c;I(b)c=[b];Y{c=1E.36(e.13.34);O(K d=[],h=0;h<c.L;h++)d.U(c[h]);c=d}c=c;d=[];I(e.13.2M)c=c.1O(z());I(c.L===0)H d;O(h=0;h<c.L;h++){O(K g=c[h],i=a,k=c[h].1l,j=3W 0,l={},m=1f M("^\\\\[(?<2V>(.*?))\\\\]$"),s=1f M("(?<27>[\\\\w-]+)\\\\s*:\\\\s*(?<1T>[\\\\w-%#]+|\\\\[.*?\\\\]|\\".*?\\"|\'.*?\')\\\\s*;?","g");(j=s.X(k))!=N;){K o=j.1T.Q(/^[\'"]|[\'"]$/g,"");I(o!=N&&m.1A(o)){o=m.X(o);o=o.2V.L>0?o.2V.1e(/\\s*,\\s*/):[]}l[j.27]=o}g={1F:g,1n:C(i,l)};g.1n.1D!=N&&d.U(g)}H d},1M:6(a,b){K c=J.35(a,b),d=N,h=e.13;I(c.L!==0)O(K g=0;g<c.L;g++){b=c[g];K i=b.1F,k=b.1n,j=k.1D,l;I(j!=N){I(k["1z-1k"]=="R"||e.2v["1z-1k"]==R){d=1f e.4l(j);j="4O"}Y I(d=A(j))d=1f d;Y 6H;l=i.3X;I(h.2M){l=l;K m=x(l),s=11;I(m.1i("<![6G[")==0){m=m.4h(9);s=R}K o=m.L;I(m.1i("]]\\>")==o-3){m=m.4h(0,o-3);s=R}l=s?m:l}I((i.1t||"")!="")k.1t=i.1t;k.1D=j;d.2Q(k);b=d.2F(l);I((i.1c||"")!="")b.1c=i.1c;i.2G.74(b,i)}}},2E:6(a){w(1P,"4k",6(){e.1M(a)})}};e.2E=e.2E;e.1M=e.1M;e.2L=6(a,b,c){J.1T=a;J.P=b;J.L=a.L;J.23=c;J.1V=N};e.2L.Z.1q=6(){H J.1T};e.4l=6(a){6 b(j,l){O(K m=0;m<j.L;m++)j[m].P+=l}K c=A(a),d,h=1f e.1U.5Y,g=J,i="2F 1H 2Q".1e(" ");I(c!=N){d=1f c;O(K k=0;k<i.L;k++)(6(){K j=i[k];g[j]=6(){H h[j].1p(h,14)}})();d.28==N?1P.1X(e.13.1x.1X+(e.13.1x.4g+a)):h.2J.U({1I:d.28.17,2D:6(j){O(K l=j.17,m=[],s=d.2J,o=j.P+j.18.L,F=d.28,q,G=0;G<s.L;G++){q=y(l,s[G]);b(q,o);m=m.1O(q)}I(F.18!=N&&j.18!=N){q=y(j.18,F.18);b(q,j.P);m=m.1O(q)}I(F.1b!=N&&j.1b!=N){q=y(j.1b,F.1b);b(q,j.P+j[0].5Q(j.1b));m=m.1O(q)}O(j=0;j<m.L;j++)m[j].1V=c.1V;H m}})}};e.4j=6(){};e.4j.Z={V:6(a,b){K c=J.1n[a];c=c==N?b:c;K d={"R":R,"11":11}[c];H d==N?c:d},3Y:6(a){H 1E.4i(a)},4c:6(a,b){K c=[];I(a!=N)O(K d=0;d<a.L;d++)I(1j a[d]=="2m")c=c.1O(y(b,a[d]));H J.4e(c.6b(D))},4e:6(a){O(K b=0;b<a.L;b++)I(a[b]!==N)O(K c=a[b],d=c.P+c.L,h=b+1;h<a.L&&a[b]!==N;h++){K g=a[h];I(g!==N)I(g.P>d)1N;Y I(g.P==c.P&&g.L>c.L)a[b]=N;Y I(g.P>=c.P&&g.P<d)a[h]=N}H a},4d:6(a){K b=[],c=2u(J.V("2i-1s"));v(a,6(d,h){b.U(h+c)});H b},3U:6(a){K b=J.V("1M",[]);I(1j b!="2m"&&b.U==N)b=[b];a:{a=a.1q();K c=3W 0;O(c=c=1Q.6c(c||0,0);c<b.L;c++)I(b[c]==a){b=c;1N a}b=-1}H b!=-1},2r:6(a,b,c){a=["1s","6i"+b,"P"+a,"6r"+(b%2==0?1:2).1q()];J.3U(b)&&a.U("67");b==0&&a.U("1N");H\'<T 1g="\'+a.1K(" ")+\'">\'+c+"</T>"},3Q:6(a,b){K c="",d=a.1e("\\n").L,h=2u(J.V("2i-1s")),g=J.V("2z-1s-2t");I(g==R)g=(h+d-1).1q().L;Y I(3R(g)==R)g=0;O(K i=0;i<d;i++){K k=b?b[i]:h+i,j;I(k==0)j=e.13.1W;Y{j=g;O(K l=k.1q();l.L<j;)l="0"+l;j=l}a=j;c+=J.2r(i,k,a)}H c},49:6(a,b){a=x(a);K c=a.1e("\\n");J.V("2z-1s-2t");K d=2u(J.V("2i-1s"));a="";O(K h=J.V("1D"),g=0;g<c.L;g++){K i=c[g],k=/^(&2s;|\\s)+/.X(i),j=N,l=b?b[g]:d+g;I(k!=N){j=k[0].1q();i=i.1o(j.L);j=j.Q(" ",e.13.1W)}i=x(i);I(i.L==0)i=e.13.1W;a+=J.2r(g,l,(j!=N?\'<17 1g="\'+h+\' 5N">\'+j+"</17>":"")+i)}H a},4f:6(a){H a?"<4a>"+a+"</4a>":""},4b:6(a,b){6 c(l){H(l=l?l.1V||g:g)?l+" ":""}O(K d=0,h="",g=J.V("1D",""),i=0;i<b.L;i++){K k=b[i],j;I(!(k===N||k.L===0)){j=c(k);h+=u(a.1o(d,k.P-d),j+"48")+u(k.1T,j+k.23);d=k.P+k.L+(k.75||0)}}h+=u(a.1o(d),c()+"48");H h},1H:6(a){K b="",c=["20"],d;I(J.V("2k")==R)J.1n.16=J.1n.1u=11;1l="20";J.V("2l")==R&&c.U("47");I((1u=J.V("1u"))==11)c.U("6S");c.U(J.V("1g-27"));c.U(J.V("1D"));a=a.Q(/^[ ]*[\\n]+|[\\n]*[ ]*$/g,"").Q(/\\r/g," ");b=J.V("43-22");I(J.V("42-45")==R)a=n(a,b);Y{O(K h="",g=0;g<b;g++)h+=" ";a=a.Q(/\\t/g,h)}a=a;a:{b=a=a;h=/<2R\\s*\\/?>|&1y;2R\\s*\\/?&1G;/2T;I(e.13.46==R)b=b.Q(h,"\\n");I(e.13.44==R)b=b.Q(h,"");b=b.1e("\\n");h=/^\\s*/;g=4Q;O(K i=0;i<b.L&&g>0;i++){K k=b[i];I(x(k).L!=0){k=h.X(k);I(k==N){a=a;1N a}g=1Q.4q(k[0].L,g)}}I(g>0)O(i=0;i<b.L;i++)b[i]=b[i].1o(g);a=b.1K("\\n")}I(1u)d=J.4d(a);b=J.4c(J.2J,a);b=J.4b(a,b);b=J.49(b,d);I(J.V("41-40"))b=E(b);1j 2H!="1d"&&2H.3S&&2H.3S.1C(/5s/)&&c.U("5t");H b=\'<T 1c="\'+t(J.1c)+\'" 1g="\'+c.1K(" ")+\'">\'+(J.V("16")?e.16.1H(J):"")+\'<3Z 5z="0" 5H="0" 5J="0">\'+J.4f(J.V("1t"))+"<3T><3P>"+(1u?\'<2d 1g="1u">\'+J.3Q(a)+"</2d>":"")+\'<2d 1g="17"><T 1g="3O">\'+b+"</T></2d></3P></3T></3Z></T>"},2F:6(a){I(a===N)a="";J.17=a;K b=J.3Y("T");b.3X=J.1H(a);J.V("16")&&w(p(b,".16"),"5c",e.16.2b);J.V("3V-17")&&w(p(b,".17"),"56",f);H b},2Q:6(a){J.1c=""+1Q.5d(1Q.5n()*5k).1q();e.1Y.2A[t(J.1c)]=J;J.1n=C(e.2v,a||{});I(J.V("2k")==R)J.1n.16=J.1n.1u=11},5j:6(a){a=a.Q(/^\\s+|\\s+$/g,"").Q(/\\s+/g,"|");H"\\\\b(?:"+a+")\\\\b"},5f:6(a){J.28={18:{1I:a.18,23:"1k"},1b:{1I:a.1b,23:"1k"},17:1f M("(?<18>"+a.18.1m+")(?<17>.*?)(?<1b>"+a.1b.1m+")","5o")}}};H e}();1j 2e!="1d"&&(2e.1v=1v);',62,441,'||||||function|||||||||||||||||||||||||||||||||||||return|if|this|var|length|XRegExp|null|for|index|replace|true||div|push|getParam|call|exec|else|prototype||false|lastIndex|config|arguments|RegExp|toolbar|code|left|captureNames|slice|right|id|undefined|split|new|class|addToken|indexOf|typeof|script|className|source|params|substr|apply|toString|String|line|title|gutter|SyntaxHighlighter|_xregexp|strings|lt|html|test|OUTSIDE_CLASS|match|brush|document|target|gt|getHtml|regex|global|join|style|highlight|break|concat|window|Math|isRegExp|throw|value|brushes|brushName|space|alert|vars|http|syntaxhighlighter|expandSource|size|css|case|font|Fa|name|htmlScript|dA|can|handler|gm|td|exports|color|in|href|first|discoveredBrushes|light|collapse|object|cache|getButtonHtml|trigger|pattern|getLineHtml|nbsp|numbers|parseInt|defaults|com|items|www|pad|highlighters|execute|focus|func|all|getDiv|parentNode|navigator|INSIDE_CLASS|regexList|hasFlag|Match|useScriptTags|hasNamedCapture|text|help|init|br|input|gi|Error|values|span|list|250|height|width|screen|top|500|tagName|findElements|getElementsByTagName|aboutDialog|_blank|appendChild|charAt|Array|copyAsGlobal|setFlag|highlighter_|string|attachEvent|nodeName|floor|backref|output|the|TypeError|sticky|Za|iterate|freezeTokens|scope|type|textarea|alexgorbatchev|version|margin|2010|005896|gs|regexLib|body|center|align|noBrush|require|childNodes|DTD|xhtml1|head|org|w3|url|preventDefault|container|tr|getLineNumbersHtml|isNaN|userAgent|tbody|isLineHighlighted|quick|void|innerHTML|create|table|links|auto|smart|tab|stripBrs|tabs|bloggerMode|collapsed|plain|getCodeLinesHtml|caption|getMatchesHtml|findMatches|figureOutLineNumbers|removeNestedMatches|getTitleHtml|brushNotHtmlScript|substring|createElement|Highlighter|load|HtmlScript|Brush|pre|expand|multiline|min|Can|ignoreCase|find|blur|extended|toLowerCase|aliases|addEventListener|innerText|textContent|wasn|select|createTextNode|removeChild|option|same|frame|xmlns|dtd|twice|1999|equiv|meta|htmlscript|transitional|1E3|expected|PUBLIC|DOCTYPE|on|W3C|XHTML|TR|EN|Transitional||configured|srcElement|Object|after|run|dblclick|matchChain|valueOf|constructor|default|switch|click|round|execAt|forHtmlScript|token|gimy|functions|getKeywords|1E6|escape|within|random|sgi|another|finally|supply|MSIE|ie|toUpperCase|catch|returnValue|definition|event|border|imsx|constructing|one|Infinity|from|when|Content|cellpadding|flags|cellspacing|try|xhtml|Type|spaces|2930402|hosted_button_id|lastIndexOf|donate|active|development|keep|to|xclick|_s|Xml|please|like|you|paypal|cgi|cmd|webscr|bin|highlighted|scrollbars|aspScriptTags|phpScriptTags|sort|max|scriptScriptTags|toolbar_item|_|command|command_|number|getElementById|doubleQuotedString|singleLinePerlComments|singleLineCComments|multiLineCComments|singleQuotedString|multiLineDoubleQuotedString|xmlComments|alt|multiLineSingleQuotedString|If|https|1em|000|fff|background|5em|xx|bottom|75em|Gorbatchev|large|serif|CDATA|continue|utf|charset|content|About|family|sans|Helvetica|Arial|Geneva|3em|nogutter|Copyright|syntax|close|write|2004|Alex|open|JavaScript|highlighter|July|02|replaceChild|offset|83'.split('|'),0,{})) | SyntaxHighlighter
http://alexgorbatchev.com/SyntaxHighlighter
SyntaxHighlighter is donationware. If you are using it, please donate.
http://alexgorbatchev.com/SyntaxHighlighter/donate.html
@version
3.0.83 (July 02 2010)
@copyright
Copyright (C) 2004-2010 Alex Gorbatchev.
@license
Dual licensed under the MIT and GPL licenses. | e ( c ) | javascript | CreateJS/SoundJS | tutorials/_shared/SyntaxHighlighter/shCore.js | https://github.com/CreateJS/SoundJS/blob/master/tutorials/_shared/SyntaxHighlighter/shCore.js | MIT |
function FlashAudioSoundInstance(src, startTime, duration, playbackResource) {
this.AbstractSoundInstance_constructor(src, startTime, duration, playbackResource);
// Public Properties
/**
* ID used to facilitate communication with flash.
* Not doc'd because this should not be altered externally
* #property flashId
* @type {String}
*/
this.flashId = null; // To communicate with Flash
if(s._flash == null) { s._instances.push(this); }
}; | FlashAudioSoundInstance extends the base api of {{#crossLink "AbstractSoundInstance"}}{{/crossLink}} and is used by
{{#crossLink "FlashAudioPlugin"}}{{/crossLink}}.
NOTE audio control is shuttled to a flash player instance via the flash reference.
@param {String} src The path to and file name of the sound.
@param {Number} startTime Audio sprite property used to apply an offset, in milliseconds.
@param {Number} duration Audio sprite property used to set the time the clip plays for, in milliseconds.
@param {Object} playbackResource Any resource needed by plugin to support audio playback.
@class FlashAudioSoundInstance
@extends AbstractSoundInstance
@constructor | FlashAudioSoundInstance ( src , startTime , duration , playbackResource ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioSoundInstance.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioSoundInstance.js | MIT |
s.setFlash = function(flash) {
s._flash = flash;
for(var i = s._instances.length; i--; ) {
var o = s._instances.pop();
o._setDurationFromSource();
}
}; | Set the Flash instance on the class, and start loading on any instances that had load called
before flash was ready
#method setFlash
@param flash Flash instance that handles loading and playback | s.setFlash ( flash ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioSoundInstance.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioSoundInstance.js | MIT |
p.handleSoundFinished = function () {
this._loop = 0;
this._handleSoundComplete();
}; | Called from Flash. Lets us know flash has finished playing a sound.
#method handleSoundFinished
@protected | p.handleSoundFinished ( ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioSoundInstance.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioSoundInstance.js | MIT |
p.handleSoundLoop = function () {
this._loop--;
this._sendEvent("loop");
}; | Called from Flash. Lets us know that flash has played a sound to completion and is looping it.
#method handleSoundLoop
@protected | p.handleSoundLoop ( ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioSoundInstance.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioSoundInstance.js | MIT |
function FlashAudioPlugin() {
this.AbstractPlugin_constructor();
// Public Properties
/**
* A developer flag to output all flash events to the console (if it exists). Used for debugging.
*
* createjs.Sound.activePlugin.showOutput = true;
*
* @property showOutput
* @type {Boolean}
* @default false
*/
this.showOutput = false;
//Private Properties
/**
* The id name of the DIV that gets created for Flash content.
* @property _CONTAINER_ID
* @type {String}
* @default flashAudioContainer
* @protected
*/
this._CONTAINER_ID = "flashAudioContainer";
/**
* The id name of the DIV wrapper that contains the Flash content.
* @property _WRAPPER_ID
* @type {String}
* @default SoundJSFlashContainer
* @protected
* @since 0.4.1
*/
this._WRAPPER_ID = "SoundJSFlashContainer";
/**
* A reference to the DIV container that gets created to hold the Flash instance.
* @property _container
* @type {HTMLDivElement}
* @protected
*/
this._container = null,
/**
* A reference to the Flash instance that gets created.
* @property flash
* @type {Object | Embed}
* @protected
*/
this._flash = null;
/**
* Determines if the Flash object has been created and initialized. This is required to make <code>ExternalInterface</code>
* calls from JavaScript to Flash.
* @property flashReady
* @type {Boolean}
* @default false
*/
this.flashReady = false;
/**
* A hash of SoundInstances indexed by the related ID in Flash. This lookup is required to connect sounds in
* JavaScript to their respective instances in Flash.
* @property _flashInstances
* @type {Object}
* @protected
*/
this._flashInstances = {};
/**
* A hash of Sound Preload instances indexed by the related ID in Flash. This lookup is required to connect
* a preloading sound in Flash with its respective instance in JavaScript.
* @property _flashPreloadInstances
* @type {Object}
* @protected
*/
this._flashPreloadInstances = {};
//TODO consider combining _flashInstances and _flashPreloadInstances into a single hash
this._capabilities = s._capabilities;
this._loaderClass = createjs.FlashAudioLoader;
this._soundInstanceClass = createjs.FlashAudioSoundInstance;
// Create DIV
var w = this.wrapper = document.createElement("div");
w.id = this._WRAPPER_ID;
w.style.position = "absolute";
w.style.marginLeft = "-1px";
w.className = this._WRAPPER_ID;
document.body.appendChild(w);
// Create Placeholder
var c = this._container = document.createElement("div");
c.id = this._CONTAINER_ID;
c.appendChild(document.createTextNode("SoundJS Flash Container"));
w.appendChild(c);
var path = s.swfPath;
var val = swfobject.embedSWF(path + "FlashAudioPlugin.swf", this._CONTAINER_ID, "1", "1",
"9.0.0", null, null, {"AllowScriptAccess" : "always"}, null,
createjs.proxy(this._handleSWFReady, this)
);
}; | Play sounds using a Flash instance. This plugin is not used by default, and must be registered manually in
{{#crossLink "Sound"}}{{/crossLink}} using the {{#crossLink "Sound/registerPlugins"}}{{/crossLink}} method. This
plugin is recommended to be included if sound support is required in older browsers such as IE8.
This plugin requires FlashAudioPlugin.swf and swfObject.js, which is compiled
into the minified FlashAudioPlugin-X.X.X.min.js file. You must ensure that {{#crossLink "FlashAudioPlugin/swfPath:property"}}{{/crossLink}}
is set when using this plugin, so that the script can find the swf.
<h4>Example</h4>
createjs.FlashAudioPlugin.swfPath = "../src/soundjs/flashaudio";
createjs.Sound.registerPlugins([createjs.WebAudioPlugin, createjs.HTMLAudioPlugin, createjs.FlashAudioPlugin]);
// Adds FlashAudioPlugin as a fallback if WebAudio and HTMLAudio do not work.
Note that the SWF is embedded into a container DIV (with an id and classname of "SoundJSFlashContainer"), and
will have an id of "flashAudioContainer". The container DIV is positioned 1 pixel off-screen to the left to avoid
showing the 1x1 pixel white square.
<h4>Known Browser and OS issues for Flash Audio</h4>
<b>All browsers</b><br />
<ul><li> There can be a delay in flash player starting playback of audio. This has been most noticeable in Firefox.
Unfortunely this is an issue with the flash player and the browser and therefore cannot be addressed by SoundJS.</li></ul>
@class FlashAudioPlugin
@extends AbstractPlugin
@constructor | FlashAudioPlugin ( ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioPlugin.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioPlugin.js | MIT |
p._handleSWFReady = function (event) {
this._flash = event.ref;
}; | The SWF used for sound preloading and playback has been initialized.
@method _handleSWFReady
@param {Object} event Contains a reference to the swf.
@protected | p._handleSWFReady ( event ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioPlugin.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioPlugin.js | MIT |
p._handleFlashReady = function () {
this.flashReady = true;
this._loaderClass.setFlash(this._flash);
this._soundInstanceClass.setFlash(this._flash);
}; | The Flash application that handles preloading and playback is ready. We wait for a callback from Flash to
ensure that everything is in place before playback begins.
@method _handleFlashReady
@protected | p._handleFlashReady ( ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioPlugin.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioPlugin.js | MIT |
p._updateVolume = function () {
var newVolume = createjs.Sound._masterMute ? 0 : this._volume;
return this._flash.setMasterVolume(newVolume);
}; | Internal function used to set the gain value for master audio. Should not be called externally.
@method _updateVolume
@return {Boolean}
@protected
@since 0.4.0 | p._updateVolume ( ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioPlugin.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioPlugin.js | MIT |
function Loader(loadItem) {
this.AbstractLoader_constructor(loadItem, false, createjs.Types.SOUND);
// Public properties
/**
* ID used to facilitate communication with flash.
* Not doc'd because this should not be altered externally
* @property flashId
* @type {String}
*/
this.flashId = null;
} | Loader provides a mechanism to preload Flash content via PreloadJS or internally. Instances are returned to
the preloader, and the load method is called when the asset needs to be requested.
@class FlashAudioLoader
@param {String} loadItem The item to be loaded
@param {Object} flash The flash instance that will do the preloading.
@extends AbstractLoader
@protected | Loader ( loadItem ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioLoader.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioLoader.js | MIT |
s.setFlash = function(flash) {
s._flash = flash;
for(var i = s._preloadInstances.length; i--; ) {
var loader = s._preloadInstances.pop();
loader.load();
}
}; | Set the Flash instance on the class, and start loading on any instances that had load called
before flash was ready
@method setFlash
@param flash Flash instance that handles loading and playback | s.setFlash ( flash ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioLoader.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioLoader.js | MIT |
p.handleProgress = function (loaded, total) {
this._sendProgress(loaded/total);
}; | called from flash when loading has progress
@method handleProgress
@param loaded
@param total
@protected | p.handleProgress ( loaded , total ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioLoader.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioLoader.js | MIT |
p.handleComplete = function () {
this._result = this._item.src;
this._sendComplete();
}; | Called from Flash when sound is loaded. Set our ready state and fire callbacks / events
@method handleComplete
@protected | p.handleComplete ( ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioLoader.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioLoader.js | MIT |
p.handleError = function (error) {
this._handleError(error);
}; | Receive error event from flash and pass it to callback.
@method handleError
@param {Event} error
@protected | p.handleError ( error ) | javascript | CreateJS/SoundJS | src/soundjs/flashaudio/FlashAudioLoader.js | https://github.com/CreateJS/SoundJS/blob/master/src/soundjs/flashaudio/FlashAudioLoader.js | MIT |
lazyLoad(args) {
lazyLoadImage(args.target, null, () => {
//callback
})
} | Lazy load the related image.
@see ../utils/image.js
It is recommended to wrap your `<img>` into an element with the
CSS class name `.c-lazy`. The CSS class name modifier `.-lazy-loaded`
will be applied on both the image and the parent wrapper.
```html
<div class="c-lazy o-ratio u-4:3">
<img data-scroll data-scroll-call="lazyLoad, Scroll, main" data-src="http://picsum.photos/640/480?v=1" alt="" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" />
</div>
```
@param {LocomotiveScroll} args - The Locomotive Scroll instance. | lazyLoad ( args ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/modules/Scroll.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/modules/Scroll.js | MIT |
const getImageMetadata = $img => ({
url: $img.src,
width: $img.naturalWidth,
height: $img.naturalHeight,
ratio: $img.naturalWidth / $img.naturalHeight,
})
/**
* Load the given image.
*
* @param {string} url - The URI to lazy load into $el.
* @param {object} options - An object of options
* @return {void}
*/
const loadImage = (url, options = {}) => { | Get an image meta data
@param {HTMLImageElement} $img - The image element.
@return {object} The given image meta data | getImageMetadata | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
function conformsToReference(font, criterion)
{
for (const [ key, value ] of Object.entries(criterion)) {
switch (key) {
case 'family': {
if (trim(font[key]) !== value) {
return false;
}
break;
}
case 'weight': {
/**
* Note concerning font weights:
* Loose equality (`==`) is used to compare numeric weights,
* a number (`400`) and a numeric string (`"400"`).
* Comparison between numeric and keyword values is neglected.
*
* @link https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#common_weight_name_mapping
*/
if (font[key] != value) {
return false;
}
break;
}
default: {
if (font[key] !== value) {
return false;
}
break;
}
}
}
return true;
} | Determines if the given font matches the given `FontFaceReference`.
@param {FontFace} font - The font to inspect.
@param {FontFaceReference} criterion - The object of property values to match.
@returns {boolean} | conformsToReference ( font , criterion ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function conformsToShorthand(font, criterion)
{
const family = trim(font.family);
if (trim(family) === criterion) {
return true;
}
if (
criterion.endsWith(trim(family)) && (
criterion.match(font.weight) ||
criterion.match(font.style)
)
) {
return true;
}
return true;
} | Determines if the given font matches the given font shorthand.
@param {FontFace} font - The font to inspect.
@param {string} criterion - The font shorthand to match.
@returns {boolean} | conformsToShorthand ( font , criterion ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function conformsToAnyReference(font, criteria)
{
for (const criterion of criteria) {
if (conformsToReference(font, criterion)) {
return true;
}
}
return false;
} | Determines if the given font matches any of the given criteria.
@param {FontFace} font - The font to inspect.
@param {FontFaceReference[]} criteria - A list of objects with property values to match.
@returns {boolean} | conformsToAnyReference ( font , criteria ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function findManyByReference(search)
{
const found = [];
for (const font of document.fonts) {
if (conformsToReference(font, search)) {
found.push(font);
}
}
return found;
} | Returns an iterator of all `FontFace` from `document.fonts` that satisfy
the provided `FontFaceReference`.
@param {FontFaceReference} font
@returns {FontFace[]} | findManyByReference ( search ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function findManyByShorthand(search)
{
const found = [];
for (const font of document.fonts) {
if (conformsToShorthand(font, search)) {
found.push(font);
}
}
return found;
} | Returns an iterator of all `FontFace` from `document.fonts` that satisfy
the provided font shorthand.
@param {string} font
@returns {FontFace[]} | findManyByShorthand ( search ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function findOneByReference(search)
{
for (const font of document.fonts) {
if (conformsToReference(font, criterion)) {
return font;
}
}
return null;
} | Returns the first `FontFace` from `document.fonts` that satisfies
the provided `FontFaceReference`.
@param {FontFaceReference} font
@returns {?FontFace} | findOneByReference ( search ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function findOneByShorthand(search)
{
for (const font of document.fonts) {
if (conformsToShorthand(font, search)) {
return font;
}
}
return null;
} | Returns the first `FontFace` from `document.fonts` that satisfies
the provided font shorthand.
Examples:
- "Roboto"
- "italic bold 16px Roboto"
@param {string} font
@returns {?FontFace} | findOneByShorthand ( search ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function getAny(search) {
if (search) {
switch (typeof search) {
case 'string':
return findOneByShorthand(search);
case 'object':
return findOneByReference(search);
}
}
throw new TypeError(
'Expected font query to be font shorthand or font reference'
);
} | Returns a `FontFace` from `document.fonts` that satisfies
the provided query.
@param {FontFaceReference|string} font - Either:
- a `FontFaceReference` object
- a font family name
- a font specification, for example "italic bold 16px Roboto"
@returns {?FontFace}
@throws {TypeError} | getAny ( search ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function getMany(queries) {
if (!Array.isArray(queries)) {
queries = [ queries ];
}
const found = new Set();
queries.forEach((search) => {
if (search) {
switch (typeof search) {
case 'string':
found.add(...findManyByShorthand(search));
return;
case 'object':
found.add(...findManyByReference(search));
return;
}
}
throw new TypeError(
'Expected font query to be font shorthand or font reference'
);
})
return [ ...found ];
} | Returns an iterator of all `FontFace` from `document.fonts` that satisfy
the provided queries.
@param {FontFaceReference|string|(FontFaceReference|string)[]} queries
@returns {FontFace[]}
@throws {TypeError} | getMany ( queries ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function hasAny(search) {
if (search instanceof FontFace) {
return document.fonts.has(search);
}
return getAny(search) != null;
} | Determines if a font face is registered.
@param {FontFace|FontFaceReference|string} search - Either:
- a `FontFace` instance
- a `FontFaceReference` object
- a font family name
- a font specification, for example "italic bold 16px Roboto"
@returns {boolean} | hasAny ( search ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
async function loadFonts(fontsToLoad, debug = false)
{
if ((fontsToLoad.size ?? fontsToLoad.length) === 0) {
throw new TypeError(
'Expected at least one font'
);
}
return await loadFontsWithAPI([ ...fontsToLoad ], debug);
} | Eagerly load fonts.
Most user agents only fetch and load fonts when they are first needed
("lazy loaded"), which can result in a perceptible delay.
This function will "eager load" the fonts.
@param {(FontFace|FontFaceReference)[]} fontsToLoad - List of fonts to load.
@param {boolean} [debug] - If TRUE, log details to the console.
@returns {Promise} | loadFonts ( fontsToLoad , debug = false ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
async function loadFontsWithAPI(fontsToLoad, debug = false)
{
debug && console.group('[loadFonts:API]', fontsToLoad.length, '/', document.fonts.size);
const fontsToBeLoaded = [];
for (const fontToLoad of fontsToLoad) {
if (fontToLoad instanceof FontFace) {
if (!document.fonts.has(fontToLoad)) {
document.fonts.add(fontToLoad);
}
fontsToBeLoaded.push(
loadFontFaceWithAPI(fontToLoad)
);
} else {
fontsToBeLoaded.push(
...getMany(fontToLoad).map((font) => loadFontFaceWithAPI(font))
);
}
}
debug && console.groupEnd();
return await Promise.all(fontsToBeLoaded);
} | Eagerly load fonts using `FontFaceSet` API.
@param {FontFaceReference[]} fontsToLoad
@param {boolean} [debug]
@returns {Promise} | loadFontsWithAPI ( fontsToLoad , debug = false ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function trim(value) {
return value.replace(/['"]+/g, '');
}
/**
* Returns a Promise that resolves with the specified fonts
* when they are done loading or failed.
*
* @param {FontFaceReference|string|(FontFaceReference|string)[]} queries
*
* @returns {Promise}
*/
async function whenReady(queries)
{
const fonts = getMany(queries);
return await Promise.all(fonts.map((font) => font.loaded));
}
export {
getAny,
getMany,
hasAny,
isFontLoadingAPIAvailable,
loadFonts,
whenReady, | Removes quotes from the the string.
When a `@font-face` is declared, the font family is sometimes
defined in quotes which end up included in the `FontFace` instance.
@param {string} value
@returns {string} | trim ( value ) | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
const isObject = x => (x && typeof x === 'object')
/**
* Determines if the argument is a function.
*
* @param {*} x - The value to be checked.
* @return {boolean}
*/
const isFunction = x => typeof x === 'function' | Determines if the argument is object-like.
A value is object-like if it's not `null` and has a `typeof` result of "object".
@param {*} x - The value to be checked.
@return {boolean} | isObject | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/is.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/is.js | MIT |
const isFunction = x => typeof x === 'function'
export { | Determines if the argument is a function.
@param {*} x - The value to be checked.
@return {boolean} | isFunction | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/is.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/is.js | MIT |
const clamp = (min = 0, max = 1, a) => Math.min(max, Math.max(min, a))
/**
* Calculate lerp
* @param {number} x - start value
* @param {number} y - end value
* @param {number} a - alpha value
* @return {number} lerp value
*/
const lerp = (x, y, a) => x * (1 - a) + y * a | Clamp value
@param {number} min - start value
@param {number} max - end value
@param {number} a - alpha value
@return {number} clamped value | clamp | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/maths.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/maths.js | MIT |
const lerp = (x, y, a) => x * (1 - a) + y * a
/**
* Calculate inverted lerp
* @param {number} x - start value
* @param {number} y - end value
* @param {number} a - alpha value
* @return {number} inverted lerp value
*/
const invlerp = (x, y, a) => clamp((a - x)/(y - x)) | Calculate lerp
@param {number} x - start value
@param {number} y - end value
@param {number} a - alpha value
@return {number} lerp value | lerp | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/maths.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/maths.js | MIT |
const invlerp = (x, y, a) => clamp((a - x)/(y - x))
/**
* Round number to the specified precision.
*
* This function is necessary because `Number.prototype.toPrecision()`
* and `Number.prototype.toFixed()`
*
* @param {number} number - The floating point number to round.
* @param {number} [precision] - The number of digits to appear after the decimal point.
* @return {number} The rounded number.
*/
const roundNumber = (number, precision = 2) => { | Calculate inverted lerp
@param {number} x - start value
@param {number} y - end value
@param {number} a - alpha value
@return {number} inverted lerp value | invlerp | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/maths.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/maths.js | MIT |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.