Files
video.js-mirror/packages/spf/docs/reference/behaviors/sync-preload.md

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.mediaElement swap or state.presentation.url change, copies the media element's authored preload into state.preload if it's a W3C value and state.preload isn't holding an extended (non-W3C) value. Author intent only: on a DOM element the preload IDL 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 a preload content attribute — a UA default is never a source. When the element has no authored W3C opinion and state.preload is undefined, backfills from config.defaultPreload (default-default 'metadata') so state.preload is never undefined in steady state.
  • Write (state → DOM) — on state.preload change or context.mediaElement swap, writes state.preload back to mediaElement.preload if 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