Skip to content

Commit

Permalink
aframevr#5364 Bugfix : The processSound callback given to playSound()…
Browse files Browse the repository at this point in the history
… before the sound was loaded will be called when loaded and not ignored anymore.
  • Loading branch information
JonathannJacobs committed Oct 18, 2023
1 parent 4858281 commit bf3e196
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports.Component = registerComponent('sound', {
this.pool = new THREE.Group();
this.loaded = false;
this.mustPlay = false;
this.processSound = undefined; // Saved callback for the mustPlay mechanic

// Don't pass evt because playSound takes a function as parameter.
this.playSoundBound = function () { self.playSound(); };
Expand Down Expand Up @@ -80,7 +81,7 @@ module.exports.Component = registerComponent('sound', {

// Remove this key from cache, otherwise we can't play it again
THREE.Cache.remove(data.src);
if (self.data.autoplay || self.mustPlay) { self.playSound(); }
if (self.data.autoplay || self.mustPlay) { self.playSound(this.processSound); }
self.el.emit('sound-loaded', self.evtDetail, false);
});
}
Expand Down Expand Up @@ -208,6 +209,9 @@ module.exports.Component = registerComponent('sound', {
if (!this.loaded) {
warn('Sound not loaded yet. It will be played once it finished loading');
this.mustPlay = true;
if(processSound){
this.processSound = processSound;
}
return;
}

Expand All @@ -231,6 +235,7 @@ module.exports.Component = registerComponent('sound', {
}

this.mustPlay = false;
this.processSound = undefined;
},

/**
Expand Down

0 comments on commit bf3e196

Please sign in to comment.