mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 22:12:48 -05:00
dispose taken sound player after it fades
This commit is contained in:
parent
7f2b9786ee
commit
c62adcab3b
2 changed files with 5 additions and 6 deletions
|
@ -113,7 +113,7 @@ class SoundPlayer extends EventEmitter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.volumeEffect) {
|
if (this.volumeEffect !== null) {
|
||||||
this.volumeEffect.connect(target);
|
this.volumeEffect.connect(target);
|
||||||
} else {
|
} else {
|
||||||
this.outputNode.disconnect();
|
this.outputNode.disconnect();
|
||||||
|
@ -133,7 +133,7 @@ class SoundPlayer extends EventEmitter {
|
||||||
|
|
||||||
this.stopImmediately();
|
this.stopImmediately();
|
||||||
|
|
||||||
if (this.volumeEffect) {
|
if (this.volumeEffect !== null) {
|
||||||
this.volumeEffect.dispose();
|
this.volumeEffect.dispose();
|
||||||
this.volumeEffect = null;
|
this.volumeEffect = null;
|
||||||
}
|
}
|
||||||
|
@ -178,9 +178,6 @@ class SoundPlayer extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.outputNode = null;
|
this.outputNode = null;
|
||||||
if (this.volumeEffect !== null) {
|
|
||||||
this.volumeEffect.dispose();
|
|
||||||
}
|
|
||||||
this.volumeEffect = null;
|
this.volumeEffect = null;
|
||||||
this.initialized = false;
|
this.initialized = false;
|
||||||
this.startingUntil = 0;
|
this.startingUntil = 0;
|
||||||
|
@ -234,6 +231,7 @@ class SoundPlayer extends EventEmitter {
|
||||||
taken.volumeEffect = new VolumeEffect(taken.audioEngine, taken, null);
|
taken.volumeEffect = new VolumeEffect(taken.audioEngine, taken, null);
|
||||||
taken.volumeEffect.connect(taken.target);
|
taken.volumeEffect.connect(taken.target);
|
||||||
taken.connect(taken.volumeEffect);
|
taken.connect(taken.volumeEffect);
|
||||||
|
taken.finished().then(() => taken.dispose());
|
||||||
|
|
||||||
taken.volumeEffect.set(0);
|
taken.volumeEffect.set(0);
|
||||||
taken.outputNode.stop(this.audioEngine.audioContext.currentTime + this.audioEngine.DECAY_TIME);
|
taken.outputNode.stop(this.audioEngine.audioContext.currentTime + this.audioEngine.DECAY_TIME);
|
||||||
|
|
|
@ -109,7 +109,7 @@ tap.test('SoundPlayer', suite => {
|
||||||
});
|
});
|
||||||
|
|
||||||
suite.test('play while playing', async t => {
|
suite.test('play while playing', async t => {
|
||||||
t.plan(14);
|
t.plan(15);
|
||||||
const log = [];
|
const log = [];
|
||||||
soundPlayer.play();
|
soundPlayer.play();
|
||||||
soundPlayer.finished().then(() => log.push('play 1 finished'));
|
soundPlayer.finished().then(() => log.push('play 1 finished'));
|
||||||
|
@ -149,6 +149,7 @@ tap.test('SoundPlayer', suite => {
|
||||||
|
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
t.equal(log[1], 'play 2 finished');
|
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.equal(log.length, 2);
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
|
Loading…
Reference in a new issue