topical media & game development
mobile-graphic-easel-examples-assets-soundjs-0.4.0.min.js / js
SoundJS
Visit http://createjs.com/ for documentation, updates and examples.
Copyright (c) 2011 gskinner.com, inc.
Distributed under the terms of the MIT license.
http://www.opensource.org/licenses/mit-license.html
*
* This notice shall be included in all copies or substantial portions of the Software.
this.createjs=this.createjs||{};
(function(){var a=function(){this.initialize()},d=a.prototype;a.initialize=function(a){a.addEventListener=d.addEventListener;a.removeEventListener=d.removeEventListener;a.removeAllEventListeners=d.removeAllEventListeners;a.hasEventListener=d.hasEventListener;a.dispatchEvent=d.dispatchEvent};d._listeners=null;d.initialize=function(){};d.addEventListener=function(a,c){var b=this._listeners;b?this.removeEventListener(a,c):b=this._listeners={};var e=b[a];e||(e=b[a]=[]);e.push(c);return c};d.removeEventListener=
function(a,c){var b=this._listeners;if(b){var e=b[a];if(e)for(var k=0,f=e.length;k<f;k++)if(e[k]==c){1==f?delete b[a]:e.splice(k,1);break}}};d.removeAllEventListeners=function(a){a?this._listeners&&delete this._listeners[a]:this._listeners=null};d.dispatchEvent=function(a,c){var b=!1,e=this._listeners;if(a&&e){"string"==typeof a&&(a={type:a});a.target=c||this;e=e[a.type];if(!e)return b;for(var e=e.slice(),k=0,f=e.length;k<f;k++){var g=e[k];g instanceof Function?b=b||g.apply(null,[a]):g.handleEvent&&
(b=b||g.handleEvent(a))}}return!!b};d.hasEventListener=function(a){var c=this._listeners;return!(!c||!c[a])};d.toString=function(){return"[EventDispatcher]"};createjs.EventDispatcher=a})();this.createjs=this.createjs||{};
(function(){function a(){throw"Sound cannot be instantiated";}function d(b,a){this.init(b,a)}function l(){}a.DELIMITER="|";a.AUDIO_TIMEOUT=8E3;a.INTERRUPT_ANY="any";a.INTERRUPT_EARLY="early";a.INTERRUPT_LATE="late";a.INTERRUPT_NONE="none";a.PLAY_INITED="playInited";a.PLAY_SUCCEEDED="playSucceeded";a.PLAY_INTERRUPTED="playInterrupted";a.PLAY_FINISHED="playFinished";a.PLAY_FAILED="playFailed";a.SUPPORTED_EXTENSIONS="mp3 ogg mpeg wav m4a mp4 aiff wma mid".split(" ");a.EXTENSION_MAP={m4a:"mp4"};a.FILE_PATTERN=
/(\w+:\/{2})?((?:\w+\.){2}\w+)?(\/?[\S]+\/|\/)?([\w\-%\.]+)(?:\.)(\w+)?(\?\S+)?/i;a.defaultInterruptBehavior=a.INTERRUPT_NONE;a.lastId=0;a.activePlugin=null;a.pluginsRegistered=!1;a.masterVolume=1;a.masterMute=!1;a.instances=[];a.idHash={};a.preloadHash={};a.defaultSoundInstance=null;a.addEventListener=null;a.removeEventListener=null;a.removeAllEventListeners=null;a.dispatchEvent=null;a.hasEventListener=null;a._listeners=null;createjs.EventDispatcher.initialize(a);a.onLoadComplete=null;a.sendLoadComplete=
function(b){if(a.preloadHash[b])for(var e=0,c=a.preloadHash[b].length;e<c;e++){var f=a.preloadHash[b][e],f={target:this,type:"loadComplete",src:f.src,id:f.id,data:f.data};a.preloadHash[b][e]=!0;a.onLoadComplete&&a.onLoadComplete(f);a.dispatchEvent(f)}};a.getPreloadHandlers=function(){return{callback:createjs.proxy(a.initLoad,a),types:["sound"],extensions:a.SUPPORTED_EXTENSIONS}};a.registerPlugin=function(b){a.pluginsRegistered=!0;return null==b?!1:b.isSupported()?(a.activePlugin=new b,!0):!1};a.registerPlugins=
function(b){for(var e=0,c=b.length;e<c;e++)if(a.registerPlugin(b[e]))return!0;return!1};a.initializeDefaultPlugins=function(){return null!=a.activePlugin?!0:a.pluginsRegistered?!1:a.registerPlugins([createjs.WebAudioPlugin,createjs.HTMLAudioPlugin])?!0:!1};a.isReady=function(){return null!=a.activePlugin};a.getCapabilities=function(){return null==a.activePlugin?null:a.activePlugin.capabilities};a.getCapability=function(b){return null==a.activePlugin?null:a.activePlugin.capabilities[b]};a.initLoad=
function(b,e,c,f){b=a.registerSound(b,c,f,!1);return null==b?!1:b};a.registerSound=function(b,e,c,f){if(!a.initializeDefaultPlugins())return!1;b instanceof Object&&(b=b.src,e=b.id,c=b.data);var g=a.parsePath(b,"sound",e,c);if(null==g)return!1;null!=e&&(a.idHash[e]=g.src);var j=null;null!=c&&(isNaN(c.channels)?isNaN(c)||(j=parseInt(c)):j=parseInt(c.channels));var h=a.activePlugin.register(g.src,j);null!=h&&(null!=h.numChannels&&(j=h.numChannels),d.create(g.src,j),null==c||!isNaN(c)?c=g.data=j||d.maxPerChannel():
c.channels=g.data.channels=j||d.maxPerChannel(),null!=h.tag?g.tag=h.tag:h.src&&(g.src=h.src),null!=h.completeHandler&&(g.completeHandler=h.completeHandler),g.type=h.type);!1!=f&&(a.preloadHash[g.src]||(a.preloadHash[g.src]=[]),a.preloadHash[g.src].push({src:b,id:e,data:c}),1==a.preloadHash[g.src].length&&a.activePlugin.preload(g.src,h));return g};a.registerManifest=function(b){for(var a=[],c=0,f=b.length;c<f;c++)a[c]=createjs.Sound.registerSound(b[c].src,b[c].id,b[c].data,b[c].preload);return a};
a.loadComplete=function(b){var e=a.parsePath(b,"sound");b=e?a.getSrcById(e.src):a.getSrcById(b);return!0==a.preloadHash[b][0]};a.parsePath=function(b,e,c,f){"string"!=typeof b&&(b=b.toString());b=b.split(a.DELIMITER);e={type:e||"sound",id:c,data:f};c=a.getCapabilities();f=0;for(var g=b.length;f<g;f++){var d=b[f],h=d.match(a.FILE_PATTERN);if(null==h)return!1;var l=h[4],h=h[5];if(c[h]&&-1<a.SUPPORTED_EXTENSIONS.indexOf(h))return e.name=l,e.src=d,e.extension=h,e}return null};a.play=function(b,e,c,f,
g,d,h){b=a.createInstance(b);a.playInstance(b,e,c,f,g,d,h)||b.playFailed();return b};a.createInstance=function(b){if(!a.initializeDefaultPlugins())return a.defaultSoundInstance;var e=a.parsePath(b,"sound");b=e?a.getSrcById(e.src):a.getSrcById(b);var e=b.lastIndexOf("."),c=b.slice(e+1);-1!=e&&-1<a.SUPPORTED_EXTENSIONS.indexOf(c)?(d.create(b),b=a.activePlugin.create(b)):b=a.defaultSoundInstance;b.uniqueId=a.lastId++;return b};a.setVolume=function(b){if(null==Number(b))return!1;b=Math.max(0,Math.min(1,
b));a.masterVolume=b;if(!this.activePlugin||!this.activePlugin.setVolume||!this.activePlugin.setVolume(b))for(var e=this.instances,c=0,f=e.length;c<f;c++)e[c].setMasterVolume(b)};a.getVolume=function(){return a.masterVolume};a.mute=function(b){this.masterMute=b;if(!this.activePlugin||!this.activePlugin.setMute||!this.activePlugin.setMute(b))for(var a=this.instances,c=0,f=a.length;c<f;c++)a[c].setMasterMute(b)};a.setMute=function(b){if(null==b||void 0==b)return!1;this.masterMute=b;if(!this.activePlugin||
!this.activePlugin.setMute||!this.activePlugin.setMute(b))for(var a=this.instances,c=0,f=a.length;c<f;c++)a[c].setMasterMute(b);return!0};a.getMute=function(){return this.masterMute};a.stop=function(){for(var b=this.instances,a=b.length;0<a;a--)b[a-1].stop()};a.playInstance=function(b,c,k,f,g,d,h){c=c||a.defaultInterruptBehavior;null==k&&(k=0);null==f&&(f=b.getPosition());null==g&&(g=0);null==d&&(d=b.getVolume());null==h&&(h=b.getPan());if(0==k){if(!a.beginPlaying(b,c,f,g,d,h))return!1}else k=setTimeout(function(){a.beginPlaying(b,
c,f,g,d,h)},k),b.delayTimeoutId=k;this.instances.push(b);return!0};a.beginPlaying=function(b,a,c,f,g,j){return!d.add(b,a)?!1:!b.beginPlaying(c,f,g,j)?(b=this.instances.indexOf(b),-1<b&&this.instances.splice(b,1),!1):!0};a.getSrcById=function(b){return null==a.idHash||null==a.idHash[b]?b:a.idHash[b]};a.playFinished=function(b){d.remove(b);b=this.instances.indexOf(b);-1<b&&this.instances.splice(b,1)};a.proxy=function(b,a){return function(){return b.apply(a,arguments)}};createjs.Sound=a;createjs.proxy=
function(b,a){var c=Array.prototype.slice.call(arguments,2);return function(){return b.apply(a,Array.prototype.slice.call(arguments,0).concat(c))}};d.channels={};d.create=function(b,a){return null==d.get(b)?(d.channels[b]=new d(b,a),!0):!1};d.add=function(b,a){var c=d.get(b.src);return null==c?!1:c.add(b,a)};d.remove=function(b){var a=d.get(b.src);if(null==a)return!1;a.remove(b);return!0};d.maxPerChannel=function(){return c.maxDefault};d.get=function(b){return d.channels[b]};var c=d.prototype={src:null,
max:null,maxDefault:100,length:0,init:function(b,a){this.src=b;this.max=a||this.maxDefault;-1==this.max&&this.max==this.maxDefault;this.instances=[]},get:function(b){return this.instances[b]},add:function(b,a){if(!this.getSlot(a,b))return!1;this.instances.push(b);this.length++;return!0},remove:function(b){b=this.instances.indexOf(b);if(-1==b)return!1;this.instances.splice(b,1);this.length--;return!0},getSlot:function(b){for(var c,d,f=0,g=this.max;f<g;f++){c=this.get(f);if(null==c)return!0;if(!(b==
a.INTERRUPT_NONE&&c.playState!=a.PLAY_FINISHED))if(0==f)d=c;else if(c.playState==a.PLAY_FINISHED||c==a.PLAY_INTERRUPTED||c==a.PLAY_FAILED)d=c;else if(b==a.INTERRUPT_EARLY&&c.getPosition()<d.getPosition()||b==a.INTERRUPT_LATE&&c.getPosition()>d.getPosition())d=c}return null!=d?(d.interrupt(),this.remove(d),!0):!1},toString:function(){return"[Sound SoundChannel]"}};a.defaultSoundInstance=new function(){this.isDefault=!0;this.addEventListener=this.removeEventListener=this.removeAllEventListener=this.dispatchEvent=
this.hasEventListener=this._listeners=this.interrupt=this.playFailed=this.pause=this.resume=this.play=this.beginPlaying=this.cleanUp=this.stop=this.setMasterVolume=this.setVolume=this.mute=this.setMute=this.getMute=this.setPan=this.getPosition=this.setPosition=function(){return!1};this.getVolume=this.getPan=this.getDuration=function(){return 0};this.playState=a.PLAY_FAILED;this.toString=function(){return"[Sound Default Sound Instance]"}};l.init=function(){var b=navigator.userAgent;l.isFirefox=-1<
b.indexOf("Firefox");l.isOpera=null!=window.opera;l.isChrome=-1<b.indexOf("Chrome");l.isIOS=-1<b.indexOf("iPod")||-1<b.indexOf("iPhone")||-1<b.indexOf("iPad");l.isAndroid=-1<b.indexOf("Android");l.isBlackberry=-1<b.indexOf("Blackberry")};l.init();createjs.Sound.BrowserDetect=l})();this.createjs=this.createjs||{};
(function(){function a(){this.init()}function d(a,b){this.init(a,b)}function l(a,b){this.init(a,b)}a.capabilities=null;a.isSupported=function(){if("file:"==location.protocol)return!1;a.generateCapabilities();return null==a.context?!1:!0};a.generateCapabilities=function(){if(null==a.capabilities){var c=document.createElement("audio");if(null==c.canPlayType)return null;if(window.webkitAudioContext)a.context=new webkitAudioContext;else if(window.AudioContext)a.context=new AudioContext;else return null;
a.capabilities={panning:!0,volume:!0,tracks:-1};for(var b=createjs.Sound.SUPPORTED_EXTENSIONS,e=createjs.Sound.EXTENSION_MAP,d=0,f=b.length;d<f;d++){var g=b[d],j=e[g]||g;a.capabilities[g]="no"!=c.canPlayType("audio/"+g)&&""!=c.canPlayType("audio/"+g)||"no"!=c.canPlayType("audio/"+j)&&""!=c.canPlayType("audio/"+j)}2>a.context.destination.numberOfChannels&&(a.capabilities.panning=!1);a.dynamicsCompressorNode=a.context.createDynamicsCompressor();a.dynamicsCompressorNode.connect(a.context.destination);
a.gainNode=a.context.createGainNode();a.gainNode.connect(a.dynamicsCompressorNode)}};a.prototype={capabilities:null,volume:1,context:null,dynamicsCompressorNode:null,gainNode:null,arrayBuffers:null,init:function(){this.capabilities=a.capabilities;this.arrayBuffers={};this.context=a.context;this.gainNode=a.gainNode;this.dynamicsCompressorNode=a.dynamicsCompressorNode},register:function(a){this.arrayBuffers[a]=!0;return{tag:new l(a,this)}},isPreloadStarted:function(a){return null!=this.arrayBuffers[a]},
isPreloadComplete:function(a){return!(null==this.arrayBuffers[a]||!0==this.arrayBuffers[a])},removeFromPreload:function(a){delete this.arrayBuffers[a]},addPreloadResults:function(a,b){this.arrayBuffers[a]=b},handlePreloadComplete:function(){createjs.Sound.sendLoadComplete(this.src)},preload:function(a){this.arrayBuffers[a]=!0;a=new l(a,this);a.onload=this.handlePreloadComplete;a.load()},create:function(a){this.isPreloadStarted(a)||this.preload(a);return new d(a,this)},setVolume:function(a){this.volume=
a;this.updateVolume();return!0},updateVolume:function(){var a=createjs.Sound.masterMute?0:this.volume;a!=this.gainNode.gain.value&&(this.gainNode.gain.value=a)},getVolume:function(){return this.volume},setMute:function(){this.updateVolume();return!0},toString:function(){return"[WebAudioPlugin]"}};createjs.WebAudioPlugin=a;d.prototype={src:null,uniqueId:-1,playState:null,owner:null,offset:0,delay:0,volume:1,pan:0,duration:0,remainingLoops:0,delayTimeoutId:null,soundCompleteTimeout:null,panNode:null,
gainNode:null,sourceNode:null,muted:!1,paused:!1,startTime:0,addEventListener:null,removeEventListener:null,removeAllEventListeners:null,dispatchEvent:null,hasEventListener:null,_listeners:null,endedHandler:null,readyHandler:null,stalledHandler:null,onReady:null,onPlaySucceeded:null,onPlayInterrupted:null,onPlayFailed:null,onComplete:null,onLoop:null,sendEvent:function(a){this.dispatchEvent({target:this,type:a})},init:function(a,b){this.owner=b;this.src=a;this.panNode=this.owner.context.createPanner();
this.gainNode=this.owner.context.createGainNode();this.gainNode.connect(this.panNode);this.owner.isPreloadComplete(this.src)&&(this.duration=1E3*this.owner.arrayBuffers[this.src].duration);this.endedHandler=createjs.proxy(this.handleSoundComplete,this);this.readyHandler=createjs.proxy(this.handleSoundReady,this);this.stalledHandler=createjs.proxy(this.handleSoundStalled,this)},cleanUp:function(){this.sourceNode&&this.sourceNode.playbackState!=this.sourceNode.UNSCHEDULED_STATE&&(this.sourceNode.noteOff(0),
this.sourceNode=null);0!=this.panNode.numberOfOutputs&&this.panNode.disconnect(0);clearTimeout(this.delayTimeoutId);clearTimeout(this.soundCompleteTimeout);null!=window.createjs&&createjs.Sound.playFinished(this)},interrupt:function(){this.playState=createjs.Sound.PLAY_INTERRUPTED;if(this.onPlayInterrupted)this.onPlayInterrupted(this);this.sendEvent("interrupted");this.cleanUp();this.paused=!1},handleSoundStalled:function(){if(null!=this.onPlayFailed)this.onPlayFailed(this);this.sendEvent("failed")},
handleSoundReady:function(){null!=window.createjs&&(this.offset>this.getDuration()?this.playFailed():(0>this.offset&&(this.offset=0),this.playState=createjs.Sound.PLAY_SUCCEEDED,this.paused=!1,this.panNode.connect(this.owner.gainNode),this.sourceNode=this.owner.context.createBufferSource(),this.sourceNode.buffer=this.owner.arrayBuffers[this.src],this.duration=1E3*this.owner.arrayBuffers[this.src].duration,this.sourceNode.connect(this.gainNode),this.soundCompleteTimeout=setTimeout(this.endedHandler,
1E3*(this.sourceNode.buffer.duration-this.offset)),this.startTime=this.owner.context.currentTime-this.offset,this.sourceNode.noteGrainOn(0,this.offset,this.sourceNode.buffer.duration-this.offset)))},play:function(a,b,e,d,f,g){this.cleanUp();createjs.Sound.playInstance(this,a,b,e,d,f,g)},beginPlaying:function(a,b,e,d){if(null!=window.createjs&&this.src){this.offset=a/1E3;this.remainingLoops=b;this.setVolume(e);this.setPan(d);if(this.owner.isPreloadComplete(this.src))return this.handleSoundReady(null),
this.onPlaySucceeded&&this.onPlaySucceeded(this),this.sendEvent("succeeded"),1;this.playFailed()}},pause:function(){return!this.paused&&this.playState==createjs.Sound.PLAY_SUCCEEDED?(this.paused=!0,this.offset=this.owner.context.currentTime-this.startTime,this.sourceNode.noteOff(0),0!=this.panNode.numberOfOutputs&&this.panNode.disconnect(),clearTimeout(this.delayTimeoutId),clearTimeout(this.soundCompleteTimeout),!0):!1},resume:function(){if(!this.paused)return!1;this.handleSoundReady(null);return!0},
stop:function(){this.playState=createjs.Sound.PLAY_FINISHED;this.cleanUp();this.offset=0;return!0},setVolume:function(a){if(null==Number(a))return!1;this.volume=a=Math.max(0,Math.min(1,a));this.updateVolume();return!0},updateVolume:function(){var a=this.muted?0:this.volume;return a!=this.gainNode.gain.value?(this.gainNode.gain.value=a,!0):!1},getVolume:function(){return this.volume},mute:function(a){this.muted=a;this.updateVolume();return!0},setMute:function(a){if(null==a||void 0==a)return!1;this.muted=
a;this.updateVolume();return!0},getMute:function(){return this.muted},setPan:function(a){if(this.owner.capabilities.panning)this.panNode.setPosition(a,0,-0.5),this.pan=a;else return!1},getPan:function(){return this.pan},getPosition:function(){return 1E3*(this.paused||null==this.sourceNode?this.offset:this.owner.context.currentTime-this.startTime)},setPosition:function(a){this.offset=a/1E3;this.sourceNode&&this.sourceNode.playbackState!=this.sourceNode.UNSCHEDULED_STATE&&(this.sourceNode.noteOff(0),
clearTimeout(this.soundCompleteTimeout));!this.paused&&this.playState==createjs.Sound.PLAY_SUCCEEDED&&this.handleSoundReady(null);return!0},getDuration:function(){return this.duration},handleSoundComplete:function(){this.offset=0;if(0!=this.remainingLoops){this.remainingLoops--;this.handleSoundReady(null);if(null!=this.onLoop)this.onLoop(this);this.sendEvent("loop")}else if(null!=window.createjs){this.playState=createjs.Sound.PLAY_FINISHED;if(null!=this.onComplete)this.onComplete(this);this.sendEvent("complete");
this.cleanUp()}},playFailed:function(){if(null!=window.createjs){this.playState=createjs.Sound.PLAY_FAILED;if(null!=this.onPlayFailed)this.onPlayFailed(this);this.sendEvent("failed");this.cleanUp()}},toString:function(){return"[WebAudioPlugin SoundInstance]"}};createjs.EventDispatcher.initialize(d.prototype);l.prototype={request:null,owner:null,progress:-1,src:null,result:null,onload:null,onprogress:null,onError:null,init:function(a,b){this.src=a;this.owner=b},load:function(a){null!=a&&(this.src=
a);this.request=new XMLHttpRequest;this.request.open("GET",this.src,!0);this.request.responseType="arraybuffer";this.request.onload=createjs.proxy(this.handleLoad,this);this.request.onError=createjs.proxy(this.handleError,this);this.request.onprogress=createjs.proxy(this.handleProgress,this);this.request.send()},handleProgress:function(a,b){this.progress=a/b;if(null!=this.onprogress)this.onprogress({loaded:a,total:b,progress:this.progress})},handleLoad:function(){a.context.decodeAudioData(this.request.response,
createjs.proxy(this.handleAudioDecoded,this),createjs.proxy(this.handleError,this))},handleAudioDecoded:function(a){this.progress=1;this.result=a;this.owner.addPreloadResults(this.src,this.result);this.onload&&this.onload()},handleError:function(a){this.owner.removeFromPreload(this.src);this.onerror&&this.onerror(a)},toString:function(){return"[WebAudioPlugin WebAudioLoader]"}}})();this.createjs=this.createjs||{};
(function(){function a(){this.init()}function d(a,c){this.init(a,c)}function l(a,c){this.init(a,c)}function c(a){this.init(a)}a.MAX_INSTANCES=30;a.capabilities=null;a.AUDIO_READY="canplaythrough";a.AUDIO_ENDED="ended";a.AUDIO_ERROR="error";a.AUDIO_STALLED="stalled";a.isSupported=function(){if(createjs.Sound.BrowserDetect.isIOS)return!1;a.generateCapabilities();return null==a.tag||null==a.capabilities?!1:!0};a.generateCapabilities=function(){if(null==a.capabilities){var b=a.tag=document.createElement("audio");
if(null==b.canPlayType)return null;a.capabilities={panning:!0,volume:!0,tracks:-1};for(var c=createjs.Sound.SUPPORTED_EXTENSIONS,d=createjs.Sound.EXTENSION_MAP,f=0,g=c.length;f<g;f++){var j=c[f],h=d[j]||j;a.capabilities[j]="no"!=b.canPlayType("audio/"+j)&&""!=b.canPlayType("audio/"+j)||"no"!=b.canPlayType("audio/"+h)&&""!=b.canPlayType("audio/"+h)}}};a.prototype={capabilities:null,audioSources:null,defaultNumChannels:2,init:function(){this.capabilities=a.capabilities;this.audioSources={}},register:function(a,
e){this.audioSources[a]=!0;for(var d=c.get(a),f=null,g=e||this.defaultNumChannels,j=0;j<g;j++)f=this.createTag(a),d.add(f);return{tag:f,numChannels:g}},createTag:function(a){var c=document.createElement("audio");c.autoplay=!1;c.preload="none";c.src=a;return c},create:function(a){if(!this.isPreloadStarted(a)){var e=c.get(a),k=this.createTag(a);e.add(k);this.preload(a,{tag:k})}return new d(a,this)},isPreloadStarted:function(a){return null!=this.audioSources[a]},preload:function(a,c){this.audioSources[a]=
!0;new l(a,c.tag)},toString:function(){return"[HTMLAudioPlugin]"}};createjs.HTMLAudioPlugin=a;d.prototype={src:null,uniqueId:-1,playState:null,owner:null,loaded:!1,offset:0,delay:0,volume:1,pan:0,duration:0,remainingLoops:0,delayTimeoutId:null,tag:null,muted:!1,paused:!1,addEventListener:null,removeEventListener:null,removeAllEventListeners:null,dispatchEvent:null,hasEventListener:null,_listeners:null,onComplete:null,onLoop:null,onReady:null,onPlayFailed:null,onPlayInterrupted:null,onPlaySucceeded:null,
endedHandler:null,readyHandler:null,stalledHandler:null,init:function(a,c){this.src=a;this.owner=c;this.endedHandler=createjs.proxy(this.handleSoundComplete,this);this.readyHandler=createjs.proxy(this.handleSoundReady,this);this.stalledHandler=createjs.proxy(this.handleSoundStalled,this)},sendEvent:function(a){this.dispatchEvent({target:this,type:a})},cleanUp:function(){var a=this.tag;if(null!=a){a.pause();try{a.currentTime=0}catch(e){}a.removeEventListener(createjs.HTMLAudioPlugin.AUDIO_ENDED,this.endedHandler,
!1);a.removeEventListener(createjs.HTMLAudioPlugin.AUDIO_READY,this.readyHandler,!1);c.setInstance(this.src,a);this.tag=null}clearTimeout(this.delayTimeoutId);null!=window.createjs&&createjs.Sound.playFinished(this)},interrupt:function(){if(null!=this.tag){this.playState=createjs.Sound.PLAY_INTERRUPTED;if(this.onPlayInterrupted)this.onPlayInterrupted(this);this.sendEvent("interrupted");this.cleanUp();this.paused=!1}},play:function(a,c,d,f,g,j){this.cleanUp();createjs.Sound.playInstance(this,a,c,d,
f,g,j)},beginPlaying:function(a,e,d){if(null==window.createjs)return-1;var f=this.tag=c.getInstance(this.src);if(null==f)return this.playFailed(),-1;this.duration=1E3*this.tag.duration;f.addEventListener(createjs.HTMLAudioPlugin.AUDIO_ENDED,this.endedHandler,!1);this.offset=a;this.volume=d;this.updateVolume();this.remainingLoops=e;4!==f.readyState?(f.addEventListener(createjs.HTMLAudioPlugin.AUDIO_READY,this.readyHandler,!1),f.addEventListener(createjs.HTMLAudioPlugin.AUDIO_STALLED,this.stalledHandler,
!1),f.load()):this.handleSoundReady(null);this.onPlaySucceeded&&this.onPlaySucceeded(this);this.sendEvent("succeeded");return 1},handleSoundStalled:function(){if(null!=this.onPlayFailed)this.onPlayFailed(this);this.sendEvent("failed");this.cleanUp()},handleSoundReady:function(){null!=window.createjs&&(this.playState=createjs.Sound.PLAY_SUCCEEDED,this.paused=!1,this.tag.removeEventListener(createjs.HTMLAudioPlugin.AUDIO_READY,this.readyHandler,!1),this.offset>=this.getDuration()?this.playFailed():
(0<this.offset&&(this.tag.currentTime=0.0010*this.offset),-1==this.remainingLoops&&(this.tag.loop=!0),this.tag.play()))},pause:function(){return!this.paused&&this.playState==createjs.Sound.PLAY_SUCCEEDED&&null!=this.tag?(this.paused=!0,this.tag.pause(),clearTimeout(this.delayTimeoutId),!0):!1},resume:function(){if(!this.paused||null==this.tag)return!1;this.paused=!1;this.tag.play();return!0},stop:function(){this.offset=0;this.pause();this.playState=createjs.Sound.PLAY_FINISHED;this.cleanUp();return!0},
setMasterVolume:function(){this.updateVolume();return!0},setVolume:function(a){if(null==Number(a))return!1;this.volume=a=Math.max(0,Math.min(1,a));this.updateVolume();return!0},updateVolume:function(){if(null!=this.tag){var a=this.muted||createjs.Sound.masterMute?0:this.volume*createjs.Sound.masterVolume;a!=this.tag.volume&&(this.tag.volume=a);return!0}return!1},getVolume:function(){return this.volume},mute:function(a){this.muted=a;this.updateVolume();return!0},setMasterMute:function(){this.updateVolume();
return!0},setMute:function(a){if(null==a||void 0==a)return!1;this.muted=a;this.updateVolume();return!0},getMute:function(){return this.muted},setPan:function(){return!1},getPan:function(){return 0},getPosition:function(){return null==this.tag?this.offset:1E3*this.tag.currentTime},setPosition:function(a){if(null==this.tag)this.offset=a;else try{this.tag.currentTime=0.0010*a}catch(c){return!1}return!0},getDuration:function(){return this.duration},handleSoundComplete:function(){this.offset=0;if(0!=this.remainingLoops){this.remainingLoops--;
this.tag.play();if(null!=this.onLoop)this.onLoop(this);this.sendEvent("loop")}else if(null!=window.createjs){this.playState=createjs.Sound.PLAY_FINISHED;if(null!=this.onComplete)this.onComplete(this);this.sendEvent("complete");this.cleanUp()}},playFailed:function(){if(null!=window.createjs){this.playState=createjs.Sound.PLAY_FAILED;if(null!=this.onPlayFailed)this.onPlayFailed(this);this.sendEvent("failed");this.cleanUp()}},toString:function(){return"[HTMLAudioPlugin SoundInstance]"}};createjs.EventDispatcher.initialize(d.prototype);
l.prototype={src:null,tag:null,preloadTimer:null,loadedHandler:null,init:function(a,c){this.src=a;this.tag=c;this.preloadTimer=setInterval(createjs.proxy(this.preloadTick,this),200);this.loadedHandler=createjs.proxy(this.sendLoadedEvent,this);this.tag.addEventListener&&this.tag.addEventListener("canplaythrough",this.loadedHandler);this.tag.onreadystatechange=createjs.proxy(this.sendLoadedEvent,this);this.tag.preload="auto";this.tag.src=a;this.tag.load()},preloadTick:function(){var a=this.tag.buffered,
c=this.tag.duration;0<a.length&&a.end(0)>=c-1&&this.handleTagLoaded()},handleTagLoaded:function(){clearInterval(this.preloadTimer)},sendLoadedEvent:function(){this.tag.removeEventListener&&this.tag.removeEventListener("canplaythrough",this.loadedHandler);this.tag.onreadystatechange=null;createjs.Sound.sendLoadComplete(this.src)},toString:function(){return"[HTMLAudioPlugin HTMLAudioLoader]"}};c.tags={};c.get=function(a){var d=c.tags[a];null==d&&(d=c.tags[a]=new c(a));return d};c.getInstance=function(a){a=
c.tags[a];return null==a?null:a.get()};c.setInstance=function(a,d){var k=c.tags[a];return null==k?null:k.set(d)};c.prototype={src:null,length:0,available:0,tags:null,init:function(a){this.src=a;this.tags=[]},add:function(a){this.tags.push(a);this.length++;this.available++},get:function(){if(0==this.tags.length)return null;this.available=this.tags.length;var a=this.tags.pop();null==a.parentNode&&document.body.appendChild(a);return a},set:function(a){-1==this.tags.indexOf(a)&&this.tags.push(a);this.available=
this.tags.length},toString:function(){return"[HTMLAudioPlugin TagPool]"}}})();(function(){var a=this.createjs=this.createjs||{},a=a.SoundJS=a.SoundJS||{};a.version="0.4.0";a.buildDate="Mon, 11 Feb 2013 22:33:11 GMT"})();
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.