Skip to content

Commit

Permalink
Merge pull request #1106 from alvov/issue928
Browse files Browse the repository at this point in the history
Fix: Sounds stop playing after context is interrupted (fixes #928)
  • Loading branch information
goldfire authored May 17, 2020
2 parents e580f8e + 67cd6ce commit 894b1e9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,14 +482,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;
Expand All @@ -506,10 +511,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';

Expand Down Expand Up @@ -868,7 +873,7 @@
}
};

if (Howler.state === 'running') {
if (Howler.state === 'running' && Howler.ctx.state !== 'interrupted') {
playWebAudio();
} else {
self._playLock = true;
Expand Down

0 comments on commit 894b1e9

Please sign in to comment.