mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-14 18:01:20 +08:00
4a04b9381b
`bindMediaMetadataListeners` set `preload="auto"` and called `load()` on every `<video>`/`<audio>` in the document, unconditionally, with no window check and no distinct-source check. Every clip in a composition was told to buffer its full source before the playhead was consulted at all. Media is now fetched as the playhead approaches it. A clip whose window overlaps ten seconds ahead or two behind is raised to `preload="auto"` and loaded; the rest stay unfetched, except clips with no authored `data-duration`, held at `metadata` because their window can only come from the source. One `load()` per distinct source, so seven clips on one file are one fetch rather than seven. Half the fix has to happen at parse time. Setting `preload` at DOMContentLoaded loses the race against the resource-selection task the parser already queued: deferring only at init left 30 of the fixture's 56 elements already fetching, deferring as each element is parsed left 1. So the media registry's MutationObserver is installed from the runtime entry, at script evaluation, and marks each new element `preload="none"` unless the author asked for `preload` or `autoplay` itself. Render capture is exempt on both render signals and keeps the eager fetch: it screenshots whatever the browser has decoded when the frame is taken, so an unbuffered element there is a silent or black export. Studio's asset overlay asked whether *every* media element was buffered — an invariant this deliberately breaks, which held the overlay for its full 10 s cap and polled the document 100 times getting there. It now asks only about elements the runtime promoted. Open window of the runtime-cost gate, on the same machine and session: each media source fetched 8.0x before, 2.38x after (64 requests to 19). Of the 19, five come from the preview iframe (63 before) and fourteen from the Studio document, which U5 owns — the 1.2x budget is not reachable until that half lands.