Resume AudioContext on visibilitychange to fix SFX on mobile after tab switch
This commit is contained in:
@@ -120,6 +120,13 @@ const SFX = (() => {
|
|||||||
return ctx;
|
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 */
|
/* Core: play a tone with envelope */
|
||||||
function tone(freq, type, vol, attack, sustain, release, when) {
|
function tone(freq, type, vol, attack, sustain, release, when) {
|
||||||
const c = getCtx();
|
const c = getCtx();
|
||||||
|
|||||||
Reference in New Issue
Block a user