Skip to content

Commit

Permalink
Monkey patch fix for SoundJS
Browse files Browse the repository at this point in the history
Modified to survive our compiler.

More info here: CreateJS/SoundJS#269
  • Loading branch information
NeilFraser committed Nov 27, 2021
1 parent cef3948 commit 7ec93db
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions appengine/music/js/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ Music.importSounds = function() {
* Register the sounds.
*/
Music.registerSounds = function() {
// The packaged version of _handlePreloadComplete occasionally throws errors:
// TypeError: Cannot read properties of null (reading '1')
// A fix has been created, but isn't yet compiled into the package:
// https://github.com/CreateJS/SoundJS/issues/269
// Monkey-patch the fix.
createjs['AbstractPlugin'].prototype['_handlePreloadComplete'] = function(e) {
var src = e.target.getItem().src;
var result = e.result;
var instances = this['_soundInstances'][src];
this['_audioSources'][src] = result;

if (instances != null && instances.length > 0) {
for (var i=0, l=instances.length; i<l; i++) {
instances[i]['playbackResource'] = result;
}
}
this['_soundInstances'][src] = null;
};

var assetsPath = 'third-party/soundfonts/';
var instruments = ['piano', 'trumpet', 'violin', 'drum',
'flute', 'banjo', 'guitar', 'choir'];
Expand Down

0 comments on commit 7ec93db

Please sign in to comment.