dispose taken sound player after it fades

This commit is contained in:
Corey Frang 2018-06-20 14:20:11 -04:00 committed by Michael "Z" Goddard
parent 7f2b9786ee
commit c62adcab3b
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
2 changed files with 5 additions and 6 deletions

View file

@ -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);

View file

@ -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();