diff --git a/src/soundjs/Sound.js b/src/soundjs/Sound.js index 13882bfe..3e863cf3 100644 --- a/src/soundjs/Sound.js +++ b/src/soundjs/Sound.js @@ -1,1802 +1,141 @@ -/* - * Sound - * Visit http://createjs.com/ for documentation, updates and examples. - * - * - * Copyright (c) 2012 gskinner.com, inc. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - // namespace: this.createjs = this.createjs || {}; -/** - * The SoundJS library manages the playback of audio on the web. It works via plugins which abstract the actual audio - * implementation, so playback is possible on any platform without specific knowledge of what mechanisms are necessary - * to play sounds. - * - * To use SoundJS, use the public API on the {{#crossLink "Sound"}}{{/crossLink}} class. This API is for: - * - * - * Controlling Sounds
- * Playing sounds creates {{#crossLink "AbstractSoundInstance"}}{{/crossLink}} instances, which can be controlled - * individually. - * - * - *

Example

- * - * createjs.Sound.alternateExtensions = ["mp3"]; - * createjs.Sound.on("fileload", this.loadHandler, this); - * createjs.Sound.registerSound("path/to/mySound.ogg", "sound"); - * function loadHandler(event) { - * // This is fired for each sound that is registered. - * var instance = createjs.Sound.play("sound"); // play using id. Could also use full sourcepath or event.src. - * instance.on("complete", this.handleComplete, this); - * instance.volume = 0.5; - * } - * - *

Browser Support

- * Audio will work in browsers which support Web Audio (http://caniuse.com/audio-api) - * or HTMLAudioElement (http://caniuse.com/audio). - * A Flash fallback can be used for any browser that supports the Flash player, and the Cordova plugin can be used in - * any webview that supports Cordova.Media. - * IE8 and earlier are not supported, even with the Flash fallback. To support earlier browsers, you can use an older - * version of SoundJS (version 0.5.2 and earlier). - * - * @module SoundJS - * @main SoundJS - */ - -(function () { +createjs.Sound = (function () { "use strict"; - /** - * The Sound class is the public API for creating sounds, controlling the overall sound levels, and managing plugins. - * All Sound APIs on this class are static. - * - * Registering and Preloading
- * Before you can play a sound, it must be registered. You can do this with {{#crossLink "Sound/registerSound"}}{{/crossLink}}, - * or register multiple sounds using {{#crossLink "Sound/registerSounds"}}{{/crossLink}}. If you don't register a - * sound prior to attempting to play it using {{#crossLink "Sound/play"}}{{/crossLink}} or create it using {{#crossLink "Sound/createInstance"}}{{/crossLink}}, - * the sound source will be automatically registered but playback will fail as the source will not be ready. If you use - * PreloadJS, registration is handled for you when the sound is - * preloaded. It is recommended to preload sounds either internally using the register functions or externally using - * PreloadJS so they are ready when you want to use them. - * - * Playback
- * To play a sound once it's been registered and preloaded, use the {{#crossLink "Sound/play"}}{{/crossLink}} method. - * This method returns a {{#crossLink "AbstractSoundInstance"}}{{/crossLink}} which can be paused, resumed, muted, etc. - * Please see the {{#crossLink "AbstractSoundInstance"}}{{/crossLink}} documentation for more on the instance control APIs. - * - * Plugins
- * By default, the {{#crossLink "WebAudioPlugin"}}{{/crossLink}} or the {{#crossLink "HTMLAudioPlugin"}}{{/crossLink}} - * are used (when available), although developers can change plugin priority or add new plugins (such as the - * provided {{#crossLink "FlashAudioPlugin"}}{{/crossLink}}). Please see the {{#crossLink "Sound"}}{{/crossLink}} API - * methods for more on the playback and plugin APIs. To install plugins, or specify a different plugin order, see - * {{#crossLink "Sound/installPlugins"}}{{/crossLink}}. - * - *

Example

- * - * createjs.FlashAudioPlugin.swfPath = "../src/soundjs/flashaudio"; - * createjs.Sound.registerPlugins([createjs.WebAudioPlugin, createjs.FlashAudioPlugin]); - * createjs.Sound.alternateExtensions = ["mp3"]; - * createjs.Sound.on("fileload", this.loadHandler, this); - * createjs.Sound.registerSound("path/to/mySound.ogg", "sound"); - * function loadHandler(event) { - * // This is fired for each sound that is registered. - * var instance = createjs.Sound.play("sound"); // play using id. Could also use full source path or event.src. - * instance.on("complete", this.handleComplete, this); - * instance.volume = 0.5; - * } - * - * The maximum number of concurrently playing instances of the same sound can be specified in the "data" argument - * of {{#crossLink "Sound/registerSound"}}{{/crossLink}}. Note that if not specified, the active plugin will apply - * a default limit. Currently HTMLAudioPlugin sets a default limit of 2, while WebAudioPlugin and FlashAudioPlugin set a - * default limit of 100. - * - * createjs.Sound.registerSound("sound.mp3", "soundId", 4); - * - * Sound can be used as a plugin with PreloadJS to help preload audio properly. Audio preloaded with PreloadJS is - * automatically registered with the Sound class. When audio is not preloaded, Sound will do an automatic internal - * load. As a result, it may fail to play the first time play is called if the audio is not finished loading. Use - * the {{#crossLink "Sound/fileload:event"}}{{/crossLink}} event to determine when a sound has finished internally - * preloading. It is recommended that all audio is preloaded before it is played. - * - * var queue = new createjs.LoadQueue(); - * queue.installPlugin(createjs.Sound); - * - * Audio Sprites
- * SoundJS has added support for {{#crossLink "AudioSprite"}}{{/crossLink}}, available as of version 0.6.0. - * For those unfamiliar with audio sprites, they are much like CSS sprites or sprite sheets: multiple audio assets - * grouped into a single file. - * - *

Example

- * - * var assetsPath = "./assets/"; - * var sounds = [{ - * src:"MyAudioSprite.ogg", data: { - * audioSprite: [ - * {id:"sound1", startTime:0, duration:500}, - * {id:"sound2", startTime:1000, duration:400}, - * {id:"sound3", startTime:1700, duration: 1000} - * ]} - * } - * ]; - * createjs.Sound.alternateExtensions = ["mp3"]; - * createjs.Sound.on("fileload", loadSound); - * createjs.Sound.registerSounds(sounds, assetsPath); - * // after load is complete - * createjs.Sound.play("sound2"); - * - * Mobile Playback
- * Devices running iOS require the WebAudio context to be "unlocked" by playing at least one sound inside of a user- - * initiated event (such as touch/click). Earlier versions of SoundJS included a "MobileSafe" sample, but this is no - * longer necessary as of SoundJS 0.6.2. - * - * - * Loading Alternate Paths and Extension-less Files
- * SoundJS supports loading alternate paths and extension-less files by passing an object instead of a string for - * the `src` property, which is a hash using the format `{extension:"path", extension2:"path2"}`. These labels are - * how SoundJS determines if the browser will support the sound. This also enables multiple formats to live in - * different folders, or on CDNs, which often has completely different filenames for each file. - * - * Priority is determined by the property order (first property is tried first). This is supported by both internal loading - * and loading with PreloadJS. - * - * Note: an id is required for playback. - * - *

Example

- * - * var sounds = {path:"./audioPath/", - * manifest: [ - * {id: "cool", src: {mp3:"mp3/awesome.mp3", ogg:"noExtensionOggFile"}} - * ]}; - * - * createjs.Sound.alternateExtensions = ["mp3"]; - * createjs.Sound.addEventListener("fileload", handleLoad); - * createjs.Sound.registerSounds(sounds); - * - *

Known Browser and OS issues

- * IE 9 HTML Audio limitations
- * - * - * Firefox 25 Web Audio limitations - * + var InterruptMode = createjs.metadata.sound.InterruptMode, + PlayState = createjs.metadata.sound.PlayState, + SoundParser = createjs.soundUtils.SoundParser, + SoundFactory = createjs.soundUtils.SoundFactory; + + var _soundPlugin = SoundFactory.getSoundPlugin(), + _soundVolume = SoundFactory.getSoundVolume(), + _soundRegister = SoundFactory.getSoundRegister(), + _soundInstance = SoundFactory.getSoundInstance(), + _soundParser = SoundFactory.getSoundParser(), + _soundEventHandler = SoundFactory.getSoundEventHandler(); - * Safari limitations
- * - * - * iOS 6 Web Audio limitations
- * - * - * Android HTML Audio limitations
- * - * - * Web Audio and PreloadJS
- *