From 5b18f38f1517a8a3ee0c5bcdb1ff6be769ab0952 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 24 Mar 2018 23:40:04 +0100 Subject: [PATCH] Use audio context resume and suspend --- scripts/AudioPlayer.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/AudioPlayer.ts b/scripts/AudioPlayer.ts index b4b96f02..a3f02e0b 100644 --- a/scripts/AudioPlayer.ts +++ b/scripts/AudioPlayer.ts @@ -123,11 +123,12 @@ export class AudioPlayer { // Pause pause() { - if(!this.audioNode) { + if(!this.audioNode || !this.audioContext || this.audioContext.state === "suspended") { return } this.audioNode.playbackRate.setValueAtTime(0.0, 0) + this.audioContext.suspend() this.audioPlayerPlay.classList.remove("fade-out") this.audioPlayerPause.classList.add("fade-out") @@ -140,7 +141,12 @@ export class AudioPlayer { return } + if(!this.audioContext || this.audioContext.state === "running") { + return + } + this.audioNode.playbackRate.setValueAtTime(this.targetSpeed, 0) + this.audioContext.resume() this.audioPlayerPlay.classList.add("fade-out") this.audioPlayerPause.classList.remove("fade-out")