diff --git a/src/components/nodes/AudioInputNode.tsx b/src/components/nodes/AudioInputNode.tsx index cf8b6612..37e74645 100644 --- a/src/components/nodes/AudioInputNode.tsx +++ b/src/components/nodes/AudioInputNode.tsx @@ -52,7 +52,6 @@ export function AudioInputNode({ id, data, selected }: NodeProps { setCurrentTime(audio.currentTime); }; - audio.addEventListener("ended", handleEnded); audio.addEventListener("timeupdate", handleTimeUpdate); @@ -146,9 +145,10 @@ export function AudioInputNode({ id, data, selected }: NodeProps 0 ? currentTime / nodeData.duration : undefined; + const duration = audioRef.current?.duration; + const progress = duration && isFinite(duration) && currentTime > 0 ? currentTime / duration : undefined; drawWaveform(ctx, width, height, waveformData.peaks, progress); - }, [isPlaying, currentTime, nodeData.duration, waveformData, drawWaveform]); + }, [isPlaying, currentTime, waveformData, drawWaveform]); // Animation loop for smooth playback position updates useEffect(() => { @@ -256,16 +256,16 @@ export function AudioInputNode({ id, data, selected }: NodeProps) => { - if (!audioRef.current || !nodeData.duration || !waveformContainerRef.current) return; + if (!audioRef.current || !audioRef.current.duration || !isFinite(audioRef.current.duration) || !waveformContainerRef.current) return; const rect = waveformContainerRef.current.getBoundingClientRect(); const x = e.clientX - rect.left; const progress = x / rect.width; - const newTime = progress * nodeData.duration; + const newTime = progress * audioRef.current.duration; audioRef.current.currentTime = newTime; setCurrentTime(newTime); - }, [nodeData.duration]); + }, []); const formatTime = (seconds: number) => { const mins = Math.floor(seconds / 60); @@ -347,10 +347,10 @@ export function AudioInputNode({ id, data, selected }: NodeProps - {nodeData.duration && ( + {audioRef.current?.duration && isFinite(audioRef.current.duration) && (
)}
diff --git a/src/components/nodes/GenerateAudioNode.tsx b/src/components/nodes/GenerateAudioNode.tsx index f3bcaef9..0779d3bc 100644 --- a/src/components/nodes/GenerateAudioNode.tsx +++ b/src/components/nodes/GenerateAudioNode.tsx @@ -73,7 +73,6 @@ export function GenerateAudioNode({ id, data, selected }: NodeProps { setCurrentTime(audio.currentTime); }; - audio.addEventListener("ended", handleEnded); audio.addEventListener("timeupdate", handleTimeUpdate); @@ -159,9 +158,10 @@ export function GenerateAudioNode({ id, data, selected }: NodeProps 0 ? currentTime / nodeData.duration : undefined; + const duration = audioRef.current?.duration; + const progress = duration && isFinite(duration) && currentTime > 0 ? currentTime / duration : undefined; drawWaveform(ctx, width, height, waveformData.peaks, progress); - }, [isPlaying, currentTime, nodeData.duration, waveformData, drawWaveform]); + }, [isPlaying, currentTime, waveformData, drawWaveform]); // Animation loop for smooth playback position updates useEffect(() => { @@ -447,10 +447,10 @@ export function GenerateAudioNode({ id, data, selected }: NodeProps - {nodeData.duration && ( + {audioRef.current?.duration && isFinite(audioRef.current.duration) && (
)}