fix: fix taking a SoundPlayer's state

This commit is contained in:
Michael "Z" Goddard 2018-06-12 09:20:21 -04:00
parent 5c822e6542
commit 90589b861d
No known key found for this signature in database
GPG key ID: 762CD40DD5349872

View file

@ -102,16 +102,18 @@ class SoundPlayer extends EventEmitter {
}
const taken = new SoundPlayer(this.audioEngine, this);
taken.playbackRate = this.playbackRate;
if (this.isPlaying) {
taken.isPlaying = this.isPlaying;
taken.initialize();
taken.outputNode.disconnect();
taken.outputNode = this.outputNode;
if (this.volumeEffect !== null) {
taken.outputNode.addEventListener(ON_ENDED, taken);
taken.volumeEffect.set(this.volumeEffect.value);
}
if (this.target !== null) {
taken.connect(this.target);
}
taken.initialized = this.initialized;
taken.isPlaying = this.isPlaying;
taken.playbackRate = this.playbackRate;
}
if (this.isPlaying) {
this.emit('stop');
@ -123,9 +125,10 @@ class SoundPlayer extends EventEmitter {
this.volumeEffect.dispose();
}
this.volumeEffect = null;
this.target = null;
this.initialized = false;
this.isPlaying = false;
return taken;
}
play () {