Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Sounds stop playing after context is interrupted (fixes #928) #1106

Merged
merged 1 commit into from
May 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand Down Expand Up @@ -851,7 +856,7 @@
}
};

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