diff --git a/js/utils/synthutils.js b/js/utils/synthutils.js index 4cf0f3757b..e44f774220 100644 --- a/js/utils/synthutils.js +++ b/js/utils/synthutils.js @@ -2038,9 +2038,18 @@ function Synth() { * @memberof Synth */ this.playRecording = async () => { - const player = new Tone.Player().toDestination(); - await player.load(this.audioURL) - player.start(); + this.player = new Tone.Player().toDestination(); + await this.player.load(this.audioURL) + this.player.start(); + } + + /** + * Stops Recording + * @function + * @memberof Synth + */ + this.stopPlayBackRecording = () => { + this.player.stop(); } /** diff --git a/js/widgets/sampler.js b/js/widgets/sampler.js index 11f5eeda7e..cb25639502 100644 --- a/js/widgets/sampler.js +++ b/js/widgets/sampler.js @@ -459,6 +459,7 @@ function SampleWidget() { this._playbackBtn.classList.add("disabled"); this.is_recording = false; + this.playback = false; this._recordBtn.onclick = async () => { if (!this.is_recording) { @@ -477,10 +478,16 @@ function SampleWidget() { }; this._playbackBtn.onclick = () => { - this.sampleData = this.recordingURL; - this.sampleName = `Recorded Audio ${this.recordingURL}`; - this._addSample(); - this.activity.logo.synth.playRecording(); + if (!this.playback) { + this.sampleData = this.recordingURL; + this.sampleName = `Recorded Audio ${this.recordingURL}`; + this._addSample(); + this.activity.logo.synth.playRecording(); + this.playback = true + } else { + this.activity.logo.synth.stopPlayBackRecording(); + this.playback = false; + } }; widgetWindow.sendToCenter();