Skip to content

Commit

Permalink
Better order of stop/connect/play
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarf committed Jun 21, 2018
1 parent 65978d7 commit 7089b76
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/SoundBank.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7089b76

Please sign in to comment.