From c8f3510713f6bf96b5d97d0854a2f3ce2b32fcdd Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Thu, 21 Jun 2018 11:13:04 -0400 Subject: [PATCH] Better order of stop/connect/play --- src/SoundBank.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/SoundBank.js b/src/SoundBank.js index 044dd90..98ef0c4 100644 --- a/src/SoundBank.js +++ b/src/SoundBank.js @@ -90,11 +90,17 @@ class SoundBank { const effects = this.getSoundEffects(soundId); const player = this.getSoundPlayer(soundId); - this.playerTargets.set(soundId, target); - effects.setEffectsFromTarget(target); - effects.addSoundPlayer(player); + if (this.playerTargets.get(soundId) !== target) { + // make sure to stop the old sound, effectively "forking" the output + // when the target switches before we adjust it's effects + player.stop(); + } + this.playerTargets.set(soundId, target); + effects.addSoundPlayer(player); + effects.setEffectsFromTarget(target); player.connect(effects); + player.play(); return player.finished();