Skip to content

🎥 Make videos programmatically with React

handle ended correctly

Jonny Burger94560ec5a608
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsx
index eead17c976..d19241b5b7 100644
--- a/packages/core/src/video/VideoForRendering.tsx
+++ b/packages/core/src/video/VideoForRendering.tsx
@@ -46,12 +46,6 @@ export const VideoForRendering: React.FC<RemotionVideoProps> = ({
const frameInSeconds = frame / videoConfig.fps;
const handle = delayRender();
if (videoRef.current.currentTime === frameInSeconds) {
- // Still render if the first frame is already the end
- // For example if delaying using <Sequence />
- if (videoRef.current.ended) {
- continueRender(handle);
- return;
- }
if (videoRef.current.readyState >= 2) {
continueRender(handle);
return;
@@ -65,6 +59,7 @@ export const VideoForRendering: React.FC<RemotionVideoProps> = ({
);
return;
}
+
videoRef.current.currentTime = frameInSeconds;
videoRef.current.addEventListener(
'seeked',
@@ -73,6 +68,13 @@ export const VideoForRendering: React.FC<RemotionVideoProps> = ({
},
{once: true}
);
+ videoRef.current.addEventListener(
+ 'ended',
+ () => {
+ continueRender(handle);
+ },
+ {once: true}
+ );
videoRef.current.addEventListener(
'error',
(err) => {