From e80417fec2aca9c1207bb618bed93fa0b0bf7b04 Mon Sep 17 00:00:00 2001 From: beefchimi Date: Sat, 27 Jan 2024 14:17:44 -0500 Subject: [PATCH] :sparkles: [Website] Pause all audio when interrupted --- app/website/src/store/useEarwurmStore.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/website/src/store/useEarwurmStore.ts b/app/website/src/store/useEarwurmStore.ts index 5ce26c6..faf7b0a 100644 --- a/app/website/src/store/useEarwurmStore.ts +++ b/app/website/src/store/useEarwurmStore.ts @@ -38,6 +38,13 @@ watch(managerVolumeRef, (incomingVolume) => { metroInstance.setVolume(manager.volume); }); +document.addEventListener('visibilitychange', () => { + // Pause all playing sounds when the device is interrupted. + if (document.hidden && manager.state === 'interrupted') { + activeStacksRef.value.forEach((stackId) => manager.get(stackId)?.pause()); + } +}); + export function useEarwurmStore() { return { audioLibrary,