fix: prevent playhead marker from continuing after pause

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 <noreply@anthropic.com>
This commit is contained in:
2025-11-20 12:51:06 +01:00
parent efd4cfa607
commit 2c1e1591f6

View File

@@ -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(() => {