From 2c1e1591f667795055034c3a97c0d42d016e8ef4 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 in updatePlaybackPosition where animation frames could continue scheduling even after pause() cancelled them. Added checks to only schedule next animation frame if animationFrameRef.current is not null, ensuring the animation loop stops immediately when pause is called. This fixes the issue where the playhead marker would 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/hooks/useMultiTrackPlayer.ts b/lib/hooks/useMultiTrackPlayer.ts index 9bb0d4d..d7a1586 100644 --- a/lib/hooks/useMultiTrackPlayer.ts +++ b/lib/hooks/useMultiTrackPlayer.ts @@ -365,7 +365,10 @@ export function useMultiTrackPlayer( sourceNodesRef.current.push(source); } - animationFrameRef.current = requestAnimationFrame(updatePlaybackPosition); + // Only schedule next frame if animation frame ref is still valid (not cancelled) + if (animationFrameRef.current !== null) { + animationFrameRef.current = requestAnimationFrame(updatePlaybackPosition); + } return; } @@ -391,7 +394,10 @@ export function useMultiTrackPlayer( } setCurrentTime(newTime); - animationFrameRef.current = requestAnimationFrame(updatePlaybackPosition); + // Only schedule next frame if animation frame ref is still valid (not cancelled) + if (animationFrameRef.current !== null) { + animationFrameRef.current = requestAnimationFrame(updatePlaybackPosition); + } }, [duration]); const play = useCallback(() => {