From fa69ac649c8f78d805cb9ac0da248b23dcb7ea41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Thu, 20 Nov 2025 12:51:06 +0100 Subject: [PATCH] fix: prevent playhead marker from continuing after pause MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed race condition where animation frames could continue after pause() by adding an isPlayingRef that's checked at the start of updatePlaybackPosition. This ensures any queued animation frames will exit early if pause was called, preventing the playhead from continuing to move when audio has stopped. This fixes the issue where the playhead marker would occasionally keep moving after hitting spacebar to pause, even though no audio was playing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/hooks/useMultiTrackPlayer.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/hooks/useMultiTrackPlayer.ts b/lib/hooks/useMultiTrackPlayer.ts index 9bb0d4d..c6d4bf5 100644 --- a/lib/hooks/useMultiTrackPlayer.ts +++ b/lib/hooks/useMultiTrackPlayer.ts @@ -63,6 +63,7 @@ export function useMultiTrackPlayer( const loopStartRef = useRef(0); const loopEndRef = useRef(0); const playbackRateRef = useRef(1.0); + const isPlayingRef = useRef(false); // Keep tracksRef in sync with tracks prop useEffect(() => { @@ -319,7 +320,7 @@ export function useMultiTrackPlayer( }, []); const updatePlaybackPosition = useCallback(() => { - if (!audioContextRef.current) return; + if (!audioContextRef.current || !isPlayingRef.current) return; const elapsed = (audioContextRef.current.currentTime - startTimeRef.current) * playbackRateRef.current; const newTime = pausedAtRef.current + elapsed; @@ -500,6 +501,7 @@ export function useMultiTrackPlayer( } startTimeRef.current = audioContext.currentTime; + isPlayingRef.current = true; setIsPlaying(true); updatePlaybackPosition(); @@ -530,6 +532,7 @@ export function useMultiTrackPlayer( pausedAtRef.current = Math.min(pausedAtRef.current + elapsed, duration); setCurrentTime(pausedAtRef.current); + isPlayingRef.current = false; setIsPlaying(false); // Stop level monitoring