From 67cd6ce78024aa079a0ec40651a2267c3fb71330 Mon Sep 17 00:00:00 2001 From: artemlvov Date: Mon, 24 Dec 2018 16:30:32 +0100 Subject: [PATCH] Fix: Sounds stop playing after context is interrupted (fixes #928) --- src/howler.core.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/howler.core.js b/src/howler.core.js index 6366e6fa..5504eca1 100644 --- a/src/howler.core.js +++ b/src/howler.core.js @@ -466,14 +466,19 @@ self._suspendTimer = null; self.state = 'suspending'; - self.ctx.suspend().then(function() { + + var handleSuspension = function() { self.state = 'suspended'; if (self._resumeAfterSuspend) { delete self._resumeAfterSuspend; self._autoResume(); } - }); + }; + + // Either suspension is resolved or rejected (i.e. in case of interrupted state of audio context) + // the Howler's 'suspending' state needs to be updated. + self.ctx.suspend().then(handleSuspension, handleSuspension); }, 30000); return self; @@ -490,10 +495,10 @@ return; } - if (self.state === 'running' && self._suspendTimer) { + if (self.state === 'running' && self.ctx.state !== 'interrupted' && self._suspendTimer) { clearTimeout(self._suspendTimer); self._suspendTimer = null; - } else if (self.state === 'suspended') { + } else if (self.state === 'suspended' || self.state === 'running' && self.ctx.state === 'interrupted') { self.ctx.resume().then(function() { self.state = 'running'; @@ -851,7 +856,7 @@ } }; - if (Howler.state === 'running') { + if (Howler.state === 'running' && Howler.ctx.state !== 'interrupted') { playWebAudio(); } else { self._playLock = true;