fix: prevent playhead marker from continuing after pause
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 <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,7 @@ export function useMultiTrackPlayer(
|
||||
const loopStartRef = useRef<number>(0);
|
||||
const loopEndRef = useRef<number>(0);
|
||||
const playbackRateRef = useRef<number>(1.0);
|
||||
const isPlayingRef = useRef<boolean>(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
|
||||
|
||||
Reference in New Issue
Block a user