Resume AudioContext on visibilitychange to fix SFX on mobile after tab switch
This commit is contained in:
1 parent
c2583cd36d
commit
f5c3cb9145
1 file changed
+7
@@ -120,6 +120,13 @@ const SFX = (() => {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/* Resume AudioContext when user returns to the page on mobile */
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') {
|
||||
ctx.resume();
|
||||
}
|
||||
});
|
||||
|
||||
/* Core: play a tone with envelope */
|
||||
function tone(freq, type, vol, attack, sustain, release, when) {
|
||||
const c = getCtx();
|
||||
|
||||
Reference in new issue
Block a user