Skip to content

🎥 Make videos programmatically with React

remotion: Fix Html5Video seek callback registration race

Igor Samokhovetsdaae6fc7e87c
diff --git a/packages/core/src/video/seek-until-right.ts b/packages/core/src/video/seek-until-right.ts
index a77818d285..e97fd8d268 100644
--- a/packages/core/src/video/seek-until-right.ts
+++ b/packages/core/src/video/seek-until-right.ts
@@ -24,14 +24,6 @@ export const seekToTime = ({
};
}
- seek({
- logLevel,
- mediaRef: element,
- time: desiredTime,
- why: 'Seeking during rendering',
- mountTime,
- });
-
let cancel: number;
let cancelSeeked: null | (() => void) = null;
const prom = new Promise<number>((resolve) => {
@@ -62,6 +54,18 @@ export const seekToTime = ({
};
});
+ // Register both listeners before seeking. The compositor can present the
+ // frame while the main thread is still setting currentTime. Registering a
+ // video frame callback afterwards would wait for another frame, which a
+ // paused video will never produce.
+ seek({
+ logLevel,
+ mediaRef: element,
+ time: desiredTime,
+ why: 'Seeking during rendering',
+ mountTime,
+ });
+
return {
wait: Promise.all([prom, waitForSeekedEvent] as const).then(
([time]) => time,