mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 14:02:29 -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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue