diff --git a/packages/core/src/runtime/entry.test.ts b/packages/core/src/runtime/entry.test.ts index 341950d378..2eb279ed73 100644 --- a/packages/core/src/runtime/entry.test.ts +++ b/packages/core/src/runtime/entry.test.ts @@ -511,6 +511,26 @@ describe("runtime entry", () => { expect(loadsOf(now, soon, later)).toEqual([2, 0, 0]); }); + it("in a hidden capture page a clip with no authored length waits until due, and keeps its length once loaded", async () => { + spyLoad(); + servePreview().setAttribute("content", STUDIO_PREVIEW_CAPTURE_MODE); + const clips = videos(mountRoot(), "0", "1.5", "9"); + for (const clip of clips) clip.removeAttribute("data-duration"); + const [now, soon, later] = clips; + + await evaluateRuntime(); + expect(armed(now!, soon!, later!)).toEqual([true, false, false]); + expect(loadsOf(now!, soon!, later!)).toEqual([1, 0, 0]); + + Object.defineProperty(now!, "readyState", { value: 1 }); + Object.defineProperty(now!, "duration", { value: 2 }); + window.__player?.seek(9.4); + // The loaded clip is never reloaded, which would drop the length it is timed by; one with no length + // known that started before the playhead may still be on screen, so it loads. + expect(armed(now!, soon!, later!)).toEqual([true, true, true]); + expect(loadsOf(now!)).toEqual([1]); + }); + // Three takes of one file, each a picture and a sound, as an edit cut from a single source is. const takesOfOneFile = () => { const root = mountRoot(); diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.ts index ce5f638a95..32fe05fdff 100644 --- a/packages/core/src/runtime/init.ts +++ b/packages/core/src/runtime/init.ts @@ -3111,10 +3111,12 @@ export function initSandboxRuntimeModular(): void { }; // Where Studio's loop wraps to (window.__hf.setLoopStart); null when it does not loop. let loopStartSeconds: number | null = null; - // A clip with no authored length loads as in a render: a reload would drop the duration it is - // timed by. + // An unauthored length stays loaded (a reload drops it); on a capture page an unloaded one waits + // until due, or a thousand such clips run the renderer out of memory. const inPreloadWindow = (el: HTMLMediaElement) => - mediaDeferred && el.hasAttribute("data-start") && lengthIsAuthored(el); + mediaDeferred && + el.hasAttribute("data-start") && + (lengthIsAuthored(el) || (!loadsAhead && el.readyState === HTMLMediaElement.HAVE_NOTHING)); // Media on screen or due within the look-ahead loads; the rest stops holding a connection to // the origin that also serves Studio's thumbnails. diff --git a/packages/core/src/runtime/preloadMedia.ts b/packages/core/src/runtime/preloadMedia.ts index fb102ef4be..f9d2193dfc 100644 --- a/packages/core/src/runtime/preloadMedia.ts +++ b/packages/core/src/runtime/preloadMedia.ts @@ -10,7 +10,7 @@ import { import { createRuntimeStartTimeResolver } from "./startResolver"; import { readMediaRenderId } from "./renderFrameSibling"; import { defersMedia } from "./timedClipHide"; -import { inPlayerFrame } from "../studioPreviewMark"; +import { capturePageIn, inPlayerFrame } from "../studioPreviewMark"; import { swallow } from "./diagnostics"; import { isWebKit, mediaElementTime } from "./mediaClock"; @@ -216,7 +216,7 @@ export function deferMediaUntilDue(): void { if (!defersMedia()) return; const defer = (el: Element, startInFilm: (el: Element) => number, parsedEarly = false) => { const start = parseStrictFiniteTimingNumber(el.getAttribute("data-start")); - if (start == null || !lengthIsAuthored(el)) return; + if (start == null || (!lengthIsAuthored(el) && !capturePageIn(document))) return; const media = el as HTMLMediaElement; const authoredPreload = media.preload; const later = startInFilm(el) > 0;