fix: playback position animation frame not updating
Fixed issue where currentTime wasn't updating during playback: - Removed 'isPlaying' from updatePlaybackPosition dependencies - This was causing the RAF loop to stop when state changed - Now animation frame continues running throughout playback - Playhead now updates smoothly in waveform and timeline slider 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,7 @@ export function useMultiTrackPlayer(tracks: Track[]) {
|
|||||||
}, [tracks]);
|
}, [tracks]);
|
||||||
|
|
||||||
const updatePlaybackPosition = useCallback(() => {
|
const updatePlaybackPosition = useCallback(() => {
|
||||||
if (!audioContextRef.current || !isPlaying) return;
|
if (!audioContextRef.current) return;
|
||||||
|
|
||||||
const elapsed = audioContextRef.current.currentTime - startTimeRef.current;
|
const elapsed = audioContextRef.current.currentTime - startTimeRef.current;
|
||||||
const newTime = pausedAtRef.current + elapsed;
|
const newTime = pausedAtRef.current + elapsed;
|
||||||
@@ -43,12 +43,16 @@ export function useMultiTrackPlayer(tracks: Track[]) {
|
|||||||
setIsPlaying(false);
|
setIsPlaying(false);
|
||||||
setCurrentTime(0);
|
setCurrentTime(0);
|
||||||
pausedAtRef.current = 0;
|
pausedAtRef.current = 0;
|
||||||
|
if (animationFrameRef.current) {
|
||||||
|
cancelAnimationFrame(animationFrameRef.current);
|
||||||
|
animationFrameRef.current = null;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentTime(newTime);
|
setCurrentTime(newTime);
|
||||||
animationFrameRef.current = requestAnimationFrame(updatePlaybackPosition);
|
animationFrameRef.current = requestAnimationFrame(updatePlaybackPosition);
|
||||||
}, [isPlaying, duration]);
|
}, [duration]);
|
||||||
|
|
||||||
const play = useCallback(() => {
|
const play = useCallback(() => {
|
||||||
if (tracks.length === 0 || tracks.every(t => !t.audioBuffer)) return;
|
if (tracks.length === 0 || tracks.every(t => !t.audioBuffer)) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user