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:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user