From 90589b861d46c14d1ae7c365e875f3dd893739a6 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Tue, 12 Jun 2018 09:20:21 -0400 Subject: [PATCH] fix: fix taking a SoundPlayer's state --- src/GreenPlayer.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/GreenPlayer.js b/src/GreenPlayer.js index 1ea9a26..e6d0a41 100644 --- a/src/GreenPlayer.js +++ b/src/GreenPlayer.js @@ -102,16 +102,18 @@ class SoundPlayer extends EventEmitter { } const taken = new SoundPlayer(this.audioEngine, this); - taken.outputNode = this.outputNode; - if (this.volumeEffect !== null) { - 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) { + taken.isPlaying = this.isPlaying; + taken.initialize(); + taken.outputNode.disconnect(); + taken.outputNode = this.outputNode; + taken.outputNode.addEventListener(ON_ENDED, taken); + taken.volumeEffect.set(this.volumeEffect.value); + if (this.target !== null) { + taken.connect(this.target); + } + } 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 () {