From c62adcab3b18cd1cb26c508be8ffa73dbfb45e76 Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Wed, 20 Jun 2018 14:20:11 -0400 Subject: [PATCH] dispose taken sound player after it fades --- src/GreenPlayer.js | 8 +++----- test/SoundPlayer.js | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/GreenPlayer.js b/src/GreenPlayer.js index 32446c4..024a905 100644 --- a/src/GreenPlayer.js +++ b/src/GreenPlayer.js @@ -113,7 +113,7 @@ class SoundPlayer extends EventEmitter { return; } - if (this.volumeEffect) { + if (this.volumeEffect !== null) { this.volumeEffect.connect(target); } else { this.outputNode.disconnect(); @@ -133,7 +133,7 @@ class SoundPlayer extends EventEmitter { this.stopImmediately(); - if (this.volumeEffect) { + if (this.volumeEffect !== null) { this.volumeEffect.dispose(); this.volumeEffect = null; } @@ -178,9 +178,6 @@ class SoundPlayer extends EventEmitter { } this.outputNode = null; - if (this.volumeEffect !== null) { - this.volumeEffect.dispose(); - } this.volumeEffect = null; this.initialized = false; this.startingUntil = 0; @@ -234,6 +231,7 @@ class SoundPlayer extends EventEmitter { taken.volumeEffect = new VolumeEffect(taken.audioEngine, taken, null); taken.volumeEffect.connect(taken.target); taken.connect(taken.volumeEffect); + taken.finished().then(() => taken.dispose()); taken.volumeEffect.set(0); taken.outputNode.stop(this.audioEngine.audioContext.currentTime + this.audioEngine.DECAY_TIME); diff --git a/test/SoundPlayer.js b/test/SoundPlayer.js index d979b58..774538e 100644 --- a/test/SoundPlayer.js +++ b/test/SoundPlayer.js @@ -109,7 +109,7 @@ tap.test('SoundPlayer', suite => { }); suite.test('play while playing', async t => { - t.plan(14); + t.plan(15); const log = []; soundPlayer.play(); soundPlayer.finished().then(() => log.push('play 1 finished')); @@ -149,6 +149,7 @@ tap.test('SoundPlayer', suite => { await Promise.resolve(); t.equal(log[1], 'play 2 finished'); + t.equal(help.engineInputs.length, 1, 'old sound disconneted itself after done'); t.equal(log.length, 2); t.end();