Update
This commit is contained in:
@@ -37,6 +37,8 @@ const VideoEditor = ({ width, height }) => {
|
|||||||
|
|
||||||
const { setVideoIsPlaying } = useVideoEditorStore();
|
const { setVideoIsPlaying } = useVideoEditorStore();
|
||||||
|
|
||||||
|
const FPS_INTERVAL = 1000 / 30; // 30 FPS
|
||||||
|
|
||||||
// 🔧 FIX: Keep ref synced with state
|
// 🔧 FIX: Keep ref synced with state
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
timelineElementsRef.current = timelineElements;
|
timelineElementsRef.current = timelineElements;
|
||||||
@@ -322,7 +324,7 @@ const VideoEditor = ({ width, height }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let animationId;
|
let intervalId;
|
||||||
let isRunning = true;
|
let isRunning = true;
|
||||||
|
|
||||||
const animateFrame = () => {
|
const animateFrame = () => {
|
||||||
@@ -337,37 +339,31 @@ const VideoEditor = ({ width, height }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newTime - lastUpdateRef.current >= 0.05) {
|
lastUpdateRef.current = newTime;
|
||||||
lastUpdateRef.current = newTime;
|
setCurrentTime(newTime);
|
||||||
setCurrentTime(newTime);
|
updateVideoTimes(newTime);
|
||||||
updateVideoTimes(newTime);
|
|
||||||
|
|
||||||
if (layerRef.current) {
|
if (layerRef.current) {
|
||||||
layerRef.current.batchDraw();
|
layerRef.current.batchDraw();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isRunning) {
|
|
||||||
animationId = requestAnimationFrame(animateFrame);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
startTimeRef.current = Date.now() / 1000;
|
startTimeRef.current = Date.now() / 1000;
|
||||||
animationId = requestAnimationFrame(animateFrame);
|
intervalId = setInterval(animateFrame, FPS_INTERVAL);
|
||||||
|
|
||||||
animationRef.current = {
|
animationRef.current = {
|
||||||
stop: () => {
|
stop: () => {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
if (animationId) {
|
if (intervalId) {
|
||||||
cancelAnimationFrame(animationId);
|
clearInterval(intervalId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
if (animationId) {
|
if (intervalId) {
|
||||||
cancelAnimationFrame(animationId);
|
clearInterval(intervalId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [isPlaying, totalDuration, handlePause, updateVideoTimes]);
|
}, [isPlaying, totalDuration, handlePause, updateVideoTimes]);
|
||||||
|
|||||||
Reference in New Issue
Block a user