From 7089b76ce3005d641519a06b3deac05855399187 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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); + 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.setEffectsFromTarget(target); effects.addSoundPlayer(player); - + effects.setEffectsFromTarget(target); player.connect(effects); + player.play(); return player.finished();