Skip to content

Commit 4447e8d

Browse files
author
Andrew Start
committed
Fixed issues in WebAudio and Flash plugins.
1 parent 83fb8cb commit 4447e8d

File tree

11 files changed

+45
-18
lines changed

11 files changed

+45
-18
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ Have a look at the included examples and API documentation for more in-depth inf
5959
* The FlashAudioPlugin as3 class allows all domains to embed it.
6060
* The FlashAudioPlugin as3 class plays infinitely looping audio differently to allow it to play gaplessly - this prevents notification when a loop completes in that case.
6161
* FlashAudioPlugin can handle changing the master volume before the swf is loaded.
62+
* Changed how FlashAudioPlugin handles loaded files to avoid reloading files each time you play a sound.
6263
* Sound gets the extension and filename differently from the url so that assets retrieved via PHP service don't break it.
6364
* Added global pause() and resume() to Sound.
6465
* Added _volume as a property to AbstractPlugin so it wouldn't be undefined before setVolume() was called
6566
* Made a small change to XHRRequest's _checkError() to be more Cordova friendly.
67+
* Added a check in WebAudioSoundInstance to avoid having negative sound durations, which throws errors.

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "SoundJS",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"homepage": "https://github.com/CreateJS/SoundJS",
55
"authors": [
66
"lannymcnie",
@@ -9,7 +9,7 @@
99
"wdamien"
1010
],
1111
"description": "A Javascript library for working with Audio. Features a simple interface as the front end to multiple audio APIs via a plugin model. Currently supports WebAudio, HTML5 Audio, and a Flash fallback. Part of the CreateJS suite of libraries.",
12-
"main": "lib/soundjs-0.6.1.combined.js",
12+
"main": "lib/soundjs-0.6.2.combined.js",
1313
"keywords": [
1414
"sound",
1515
"audio",

build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "SoundJS",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"description": "SoundJS Docs",
55
"url": "http://www.createjs.com/#!/SoundJS",
66
"logo": "assets/docs-icon-SoundJS.png",

dev/com/createjs/soundjs/FlashAudioPlugin.as

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
protected var playbackTimer:Timer = new Timer(50);
4444
public var masterVolume:Number = 1;
4545
public var soundDurationHash:Object;
46+
public var soundHash:Object;
4647

4748
// UI Elements:
4849
// ** AUTO-UI ELEMENTS **
@@ -59,6 +60,7 @@
5960
lookup = {};
6061
preloadHash = {};
6162
soundDurationHash = {};
63+
soundHash = {};
6264
preloadLookup = new Dictionary();
6365
}
6466

@@ -173,12 +175,17 @@
173175

174176
protected function handleLoadComplete(event:Event):void {
175177
var id = preloadLookup[event.target];
176-
ExternalInterface.call(PRELOAD_CALLBACK, id, "handleComplete");
177178
delete preloadLookup[event.target];
178-
delete preloadHash[id];
179179
var src = soundDurationHash[id];
180+
var sound = preloadHash[id];
181+
sound.removeEventListener(ProgressEvent.PROGRESS, handleLoadProgress, false);
182+
sound.removeEventListener(Event.COMPLETE, handleLoadComplete, false);
183+
sound.removeEventListener(IOErrorEvent.IO_ERROR, handleLoadError, false);
184+
soundHash[src] = sound;
185+
delete preloadHash[id];
180186
soundDurationHash[src] = event.target.length;
181187
delete soundDurationHash[id];
188+
ExternalInterface.call(PRELOAD_CALLBACK, id, "handleComplete");
182189
log("Preload Complete", id);
183190
}
184191

@@ -477,11 +484,18 @@ class SoundWrapper extends EventDispatcher {
477484
this._startTime = startTime;
478485
this._duration = duration;
479486
this.owner = owner;
480-
481-
sound = new Sound();
482-
sound.addEventListener(IOErrorEvent.IO_ERROR, handleSoundError, false, 0, true);
483-
sound.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSoundError, false, 0, true);
484-
sound.addEventListener(Event.COMPLETE, handleSoundLoaded, false, 0, true);
487+
488+
if(owner.soundHash[src])
489+
{
490+
sound = owner.soundHash[src];
491+
}
492+
else
493+
{
494+
sound = new Sound();
495+
sound.addEventListener(IOErrorEvent.IO_ERROR, handleSoundError, false, 0, true);
496+
sound.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSoundError, false, 0, true);
497+
sound.addEventListener(Event.COMPLETE, handleSoundLoaded, false, 0, true);
498+
}
485499
}
486500

487501
/**
@@ -497,7 +511,14 @@ class SoundWrapper extends EventDispatcher {
497511
this.loop = loop;
498512
this._volume = volume;
499513
this._pan = pan;
500-
sound.load(new URLRequest(src));
514+
if(sound.bytesTotal > 0 && sound.bytesTotal == sound.bytesLoaded)
515+
{
516+
startSound(offset);
517+
}
518+
else
519+
{
520+
sound.load(new URLRequest(src));
521+
}
501522
}
502523

503524
/**

lib/FlashAudioPlugin.swf

126 Bytes
Binary file not shown.

lib/flashaudioplugin.combined.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ this.createjs = this.createjs || {};
16281628
* @type String
16291629
* @static
16301630
**/
1631-
s.version = /*=version*/"0.6.1"; // injected by build process
1631+
s.version = /*=version*/"0.6.2"; // injected by build process
16321632

16331633
/**
16341634
* The build date for this release in UTC format.
@@ -1637,6 +1637,6 @@ this.createjs = this.createjs || {};
16371637
* @type String
16381638
* @static
16391639
**/
1640-
s.buildDate = /*=date*/"Thu, 19 Feb 2015 17:32:57 GMT"; // injected by build process
1640+
s.buildDate = /*=date*/"Thu, 12 Mar 2015 16:01:48 GMT"; // injected by build process
16411641

16421642
})();

lib/flashaudioplugin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/soundjs.combined.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ this.createjs = this.createjs || {};
4949
* @type String
5050
* @static
5151
**/
52-
s.version = /*=version*/"0.6.1"; // injected by build process
52+
s.version = /*=version*/"0.6.2"; // injected by build process
5353

5454
/**
5555
* The build date for this release in UTC format.
5656
* @property buildDate
5757
* @type String
5858
* @static
5959
**/
60-
s.buildDate = /*=date*/"Thu, 19 Feb 2015 17:32:57 GMT"; // injected by build process
60+
s.buildDate = /*=date*/"Thu, 12 Mar 2015 16:01:48 GMT"; // injected by build process
6161

6262
})();
6363

@@ -6484,6 +6484,8 @@ this.createjs = this.createjs || {};
64846484
audioNode.buffer = this.playbackResource;
64856485
audioNode.connect(this.panNode);
64866486
var dur = this._duration * 0.001;
6487+
if(offset > dur)
6488+
offset = dur - 0.001;
64876489
audioNode.startTime = startTime + dur;
64886490
audioNode.start(audioNode.startTime, offset+(this._startTime*0.001), dur - offset);
64896491
return audioNode;

lib/soundjs.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
126 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)