mirror of
https://github.com/videojs/video.js.git
synced 2026-11-21 08:24:15 +01:00
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
3.5 KiB
3.5 KiB
@videojs/spf/behaviors/sync-preload
Source: src/playback/behaviors/sync-preload.ts
syncPreload
Bidirectional sync between state.preload and mediaElement.preload.
Two effects:
- Read (DOM → state) — on
context.mediaElementswap orstate.presentation.urlchange, copies the media element's authored preload intostate.preloadif it's a W3C value andstate.preloadisn't holding an extended (non-W3C) value. Author intent only: on a DOM element thepreloadIDL property reports a browser-dependent UA default even when no attribute was set ('metadata'Chromium,'auto'WebKit), so the property is consulted only when the element carries apreloadcontent attribute — a UA default is never a source. When the element has no authored W3C opinion andstate.preloadis undefined, backfills fromconfig.defaultPreload(default-default'metadata') sostate.preloadis never undefined in steady state. - Write (state → DOM) — on
state.preloadchange orcontext.mediaElementswap, writesstate.preloadback tomediaElement.preloadif the value is W3C.
Extended values (e.g. 'canplay') written externally to state.preload are sticky: read won't overwrite them, write
won't push them to the DOM. All writes are deduped to break echo loops and avoid spurious re-triggers downstream
(notably resolvePresentation, which reads state.preload).
Source: src/playback/behaviors/sync-preload.ts
Config
The setup declares config?: callers may omit it.
| Key | Type | Doc |
|---|---|---|
defaultPreload? |
StandardPreload |
Backfill applied to state.preload when neither the host element nor external code has supplied a W3C value. Defaults to 'metadata'. |
State
| Key | Access | Declared | Type | Owner | Doc |
|---|---|---|---|---|---|
preload |
writes | yes | "metadata" | "auto" | "none" | undefined |
PresentationState (behaviors/resolve-presentation) |
The preload hint the engine honors. syncPreload keeps it in step with the element's authored preload attribute (both ways) and backfills its defaultPreload when nothing supplied one; resolvePresentation holds manifest resolution while it is 'none' unless loadActivated, and the loadXSegments dispatchers choose their load mode from it. |
presentation |
reads | yes | MaybeResolvedPresentation | undefined |
PresentationState (behaviors/resolve-presentation) |
The presentation being played. A caller writes { url }; resolvePresentation parses the manifest and populates the rest. |
Context
| Key | Access | Declared | Type | Owner | Doc |
|---|---|---|---|---|---|
mediaElement |
reads | yes | MediaElementLike | undefined |
inline | The media element the engine drives. No behavior writes it: an adapter attaches one with engine.context.mediaElement.set(element) and detaches with set(undefined), as SPF's adapters do. (documented on setupMediaSource) |
Types
| Name | Kind | Description | Source |
|---|---|---|---|
SyncPreloadConfig |
interface | Config of syncPreload. | src/playback/behaviors/sync-preload.ts |