From 0ddecaa4943ddf8bed43e262a99a8f490ff74187 Mon Sep 17 00:00:00 2001 From: Tom Boullay Date: Wed, 3 Jun 2026 02:28:12 +0200 Subject: [PATCH] fix(ebike): pause repair narrator audio when leaving ebike main state --- src/components/game/EbikeRepairNarrator.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/game/EbikeRepairNarrator.tsx b/src/components/game/EbikeRepairNarrator.tsx index 6d39fb1..6cf0f44 100644 --- a/src/components/game/EbikeRepairNarrator.tsx +++ b/src/components/game/EbikeRepairNarrator.tsx @@ -46,14 +46,28 @@ export function EbikeRepairNarrator(): null { playedRef.current.add(ebikeStep); let cancelled = false; + let activeAudio: HTMLAudioElement | null = null; + void (async () => { const manifest = await loadDialogueManifest(); if (cancelled || !manifest) return; - await playDialogueById(manifest, dialogueId); + const audio = await playDialogueById(manifest, dialogueId); + if (cancelled) { + if (audio && !audio.paused) { + audio.pause(); + audio.currentTime = 0; + } + return; + } + activeAudio = audio; })(); return () => { cancelled = true; + if (activeAudio && !activeAudio.paused) { + activeAudio.pause(); + activeAudio.currentTime = 0; + } }; }, [mainState, ebikeStep]);