Skip to content

Commit ddd5d9c

Browse files
author
OJay Robinson
committed
move BrowserDetect into a utils class, change to createjs.BrowserDetect
1 parent 8baf278 commit ddd5d9c

18 files changed

Lines changed: 278 additions & 281 deletions

build/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"../src/createjs/utils/IndexOf.js",
88
"../src/createjs/utils/Proxy.js",
99
"../src/createjs/utils/definePropertySupported.js",
10+
"../src/createjs/utils/BrowserDetect.js",
1011
"../src/createjs/events/EventDispatcher.js",
1112
"../src/createjs/events/Event.js",
1213

docs/soundjs_docs-NEXT.zip

1.92 KB
Binary file not shown.

examples/AudioSprite.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h1>Sorry!</h1>
4040
displayMessage = document.getElementById("status");
4141

4242
// if this is on mobile, sounds need to be played inside of a touch event
43-
if (createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid || createjs.Sound.BrowserDetect.isBlackberry) {
43+
if (createjs.BrowserDetect.isIOS || createjs.BrowserDetect.isAndroid || createjs.BrowserDetect.isBlackberry) {
4444
//document.addEventListener("click", handleTouch, false); // works on Android, does not work on iOS
4545
displayMessage.addEventListener("click", handleTouch, false); // works on Android and iPad
4646
displayMessage.innerHTML = "Touch to Start";

examples/Game.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h1>Sorry!</h1>
110110
return;
111111
}
112112

113-
if (createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid) { // || createjs.Sound.BrowserDetect.isBlackberry OJR blackberry has not been tested yet
113+
if (createjs.BrowserDetect.isIOS || createjs.BrowserDetect.isAndroid || createjs.BrowserDetect.isBlackberry) {
114114
document.getElementById("mobile").style.display = "block";
115115
document.getElementById("content").style.display = "none";
116116
return;

examples/JustPlay.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h1>Sorry!</h1>
5353
}
5454

5555
// check if we are on a mobile device, as these currently require us to launch sound inside of a user event
56-
if (createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid) { // || createjs.Sound.BrowserDetect.isBlackberry // OJR blackberry has not been tested yet
56+
if (createjs.BrowserDetect.isIOS || createjs.BrowserDetect.isAndroid || createjs.BrowserDetect.isBlackberry) {
5757
document.getElementById("mobile").style.display = "block";
5858
document.getElementById("content").style.display = "none";
5959
return;

examples/MobileSafe.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h1>Sorry!</h1>
4040
displayMessage = document.getElementById("status");
4141

4242
// if this is on mobile, sounds need to be played inside of a touch event
43-
if (createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid || createjs.Sound.BrowserDetect.isBlackberry || createjs.Sound.BrowserDetect.isWindowPhone) {
43+
if (createjs.BrowserDetect.isIOS || createjs.BrowserDetect.isAndroid || createjs.BrowserDetect.isBlackberry || createjs.BrowserDetect.isWindowPhone) {
4444
//document.addEventListener("click", handleTouch, false); // works on Android, does not work on iOS
4545
displayMessage.addEventListener("click", handleTouch, false); // works on Android and iPad
4646
displayMessage.innerHTML = "Touch to Start";

examples/PreloadAndPlay.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ <h1>Sorry!</h1>
8686
return;
8787
}
8888

89-
if (createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid) { // || createjs.Sound.BrowserDetect.isBlackberry OJR blackberry has not been tested yet
89+
if (createjs.BrowserDetect.isIOS || createjs.BrowserDetect.isAndroid || createjs.BrowserDetect.isBlackberry) {
9090
document.getElementById("mobile").style.display = "block";
9191
document.getElementById("content").style.display = "none";
9292
return;

examples/SoundExplosion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h1>Sorry!</h1>
5454
}
5555

5656
// if this is a mobile device, we reduce the number of sparkles per click for performance reasons
57-
if (createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid || createjs.Sound.BrowserDetect.isBlackberry){
57+
if (createjs.BrowserDetect.isIOS || createjs.BrowserDetect.isAndroid || createjs.BrowserDetect.isBlackberry){
5858
sparksPerClick = sparksPerClick >> 1;
5959
}
6060

examples/SoundTween.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ <h1>Sorry!</h1>
8989
pluginStatus.innerHTML = "Active Plugin is " + createjs.Sound.activePlugin.toString(); // innerText does not work in FF
9090

9191
// check if we are on a mobile device, as these currently require us to launch sound inside of a user event
92-
if (createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid) { // || createjs.Sound.BrowserDetect.isBlackberry OJR blackberry has not been tested yet
92+
if (createjs.BrowserDetect.isIOS || createjs.BrowserDetect.isAndroid || createjs.BrowserDetect.isBlackberry) {
9393
document.getElementById("mobile").style.display = "block";
9494
document.getElementById("content").style.display = "none";
9595
return;

lib/flashaudioplugin-NEXT.combined.js

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,8 @@ this.createjs = this.createjs || {};
890890

891891
this.flashId = s._flash.preload(this.src);
892892
// Associate this preload instance with the FlashID, so callbacks can route here.
893-
// TODO change this to an event
894-
createjs.Sound.activePlugin.registerPreloadInstance(this.flashId, this);
893+
var e = new createjs.Event(createjs.FlashAudioPlugin._REG_FLASHID);
894+
this.dispatchEvent(e);
895895
};
896896

897897
p.handleProgress = function (loaded, total) {
@@ -914,6 +914,12 @@ this.createjs = this.createjs || {};
914914
this.AbstractSoundLoader__handleError(error);
915915
};
916916

917+
p.destroy = function () {
918+
var e = new createjs.Event(createjs.FlashAudioPlugin._UNREG_FLASHID);
919+
this.dispatchEvent(e);
920+
this.AbstractSoundLoader_destroy();
921+
};
922+
917923
p.toString = function () {
918924
return "[FlashAudioLoader]";
919925
};
@@ -1016,7 +1022,7 @@ this.createjs = this.createjs || {};
10161022
p._handleCleanUp = function () {
10171023
s._flash.stopSound(this.flashId);
10181024

1019-
createjs.Sound.activePlugin.unregisterSoundInstance(this.flashId); // TODO move this to plugin
1025+
this._sendEvent(createjs.FlashAudioPlugin._UNREG_FLASHID);
10201026
this.flashId = null;
10211027
};
10221028

@@ -1036,7 +1042,7 @@ this.createjs = this.createjs || {};
10361042
}
10371043

10381044
if (this._muted) {this.setMute(true);}
1039-
createjs.Sound.activePlugin.registerSoundInstance(this.flashId, this);
1045+
this._sendEvent(createjs.FlashAudioPlugin._REG_FLASHID);
10401046

10411047
this.playState = createjs.Sound.PLAY_SUCCEEDED;
10421048
this._sendEvent("succeeded");
@@ -1263,6 +1269,26 @@ this.createjs = this.createjs || {};
12631269

12641270

12651271
// Static properties
1272+
/**
1273+
* Event constant for the "registerFlashID" event for cleaner code.
1274+
* @property _REG_FLASHID
1275+
* @type {String}
1276+
* @default registerflashid
1277+
* @static
1278+
* @protected
1279+
*/
1280+
s._REG_FLASHID = "registerflashid";
1281+
1282+
/**
1283+
* Event constant for the "unregisterFlashID" event for cleaner code.
1284+
* @property _UNREG_FLASHID
1285+
* @type {String}
1286+
* @default unregisterflashid
1287+
* @static
1288+
* @protected
1289+
*/
1290+
s._UNREG_FLASHID = "unregisterflashid";
1291+
12661292
/**
12671293
* The capabilities of the plugin. This is generated via the {{#crossLink "WebAudioPlugin/_generateCapabilities"}}{{/crossLink}}
12681294
* method. Please see the Sound {{#crossLink "Sound/getCapabilities"}}{{/crossLink}} method for a list of available
@@ -1295,7 +1321,7 @@ this.createjs = this.createjs || {};
12951321
*/
12961322
s.isSupported = function () {
12971323
// there is no flash player on mobile devices
1298-
if (createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid || createjs.Sound.BrowserDetect.isBlackberry || createjs.Sound.BrowserDetect.isWindowsPhone) {return false;}
1324+
if (createjs.BrowserDetect.isIOS || createjs.BrowserDetect.isAndroid || createjs.BrowserDetect.isBlackberry || createjs.BrowserDetect.isWindowsPhone) {return false;}
12991325
s._generateCapabilities();
13001326
if (swfobject == null) {return false;}
13011327
return swfobject.hasFlashPlayerVersion("9.0.0");
@@ -1333,7 +1359,10 @@ this.createjs = this.createjs || {};
13331359
if (!this.flashReady) {
13341360
this._queuedInstances.push(src);
13351361
}
1336-
return this.AbstractPlugin_register(src, instances);
1362+
var o = this.AbstractPlugin_register(src, instances);
1363+
o.loader.addEventListener(s._REG_FLASHID, createjs.proxy(this.registerPreloadInstance, this));
1364+
o.loader.addEventListener(s._UNREG_FLASHID, createjs.proxy(this.unregisterPreloadInstance, this));
1365+
return o;
13371366
};
13381367

13391368
p.removeSound = function (src) {
@@ -1353,6 +1382,13 @@ this.createjs = this.createjs || {};
13531382
this.AbstractPlugin_removeAllSounds();
13541383
};
13551384

1385+
p.create = function (src, startTime, duration) {
1386+
var si = this.AbstractPlugin_create(src, startTime, duration);
1387+
si.addEventListener(s._REG_FLASHID, createjs.proxy(this.registerSoundInstance, this));
1388+
si.addEventListener(s._UNREG_FLASHID, createjs.proxy(this.unregisterSoundInstance, this));
1389+
return si;
1390+
};
1391+
13561392
p.toString = function () {
13571393
return "[FlashAudioPlugin]";
13581394
};
@@ -1416,17 +1452,17 @@ this.createjs = this.createjs || {};
14161452
* @param {String} flashId Used to identify the Loader.
14171453
* @param {Loader} instance The actual instance.
14181454
*/
1419-
p.registerPreloadInstance = function (flashId, instance) {
1420-
this._flashPreloadInstances[flashId] = instance;
1455+
p.registerPreloadInstance = function (event) {
1456+
this._flashPreloadInstances[event.target.flashId] = event.target;
14211457
};
14221458

14231459
/*
14241460
* Used to decouple a <code>Loader</code> instance from Flash.
14251461
* @method unregisterPreloadInstance
14261462
* @param {String} flashId Used to identify the Loader.
14271463
*/
1428-
p.unregisterPreloadInstance = function (flashId) {
1429-
delete this._flashPreloadInstances[flashId];
1464+
p.unregisterPreloadInstance = function (event) {
1465+
delete this._flashPreloadInstances[event.target.flashId];
14301466
};
14311467

14321468
/*
@@ -1435,8 +1471,8 @@ this.createjs = this.createjs || {};
14351471
* @param {String} flashId Used to identify the SoundInstance.
14361472
* @param {Loader} instance The actual instance.
14371473
*/
1438-
p.registerSoundInstance = function (flashId, instance) {
1439-
this._flashInstances[flashId] = instance;
1474+
p.registerSoundInstance = function (event) {
1475+
this._flashInstances[event.target.flashId] = event.target;
14401476
};
14411477

14421478
/*
@@ -1446,8 +1482,8 @@ this.createjs = this.createjs || {};
14461482
* @param {String} flashId Used to identify the SoundInstance.
14471483
* @param {Loader} instance The actual instance.
14481484
*/
1449-
p.unregisterSoundInstance = function (flashId) {
1450-
delete this._flashInstances[flashId];
1485+
p.unregisterSoundInstance = function (event) {
1486+
delete this._flashInstances[event.target.flashId];
14511487
};
14521488

14531489
/*

0 commit comments

Comments
 (0)