mirror of
https://github.com/videojs/video.js.git
synced 2026-11-21 08:24:15 +01:00
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
6.8 KiB
6.8 KiB
@videojs/spf/features/live
Source: src/playback/features/live.ts
liveFeature
Plays live streams: reloads their playlists, keeps the seekable window current, starts at the live edge, and keeps the playhead inside the window. Aligns separately delivered tracks on the stream's program date-times when joining mid-stream. Inert for on-demand content.
Requires:
- A consumer of
state.startPosition, such asstartPositionFeature; without one, playback starts at the window's start instead of the live edge. - A writer of
presentation.durationand of the MediaSource's duration, such ascalculateDurationFeaturewithmediaSourceFeature; without them, the stream never gets its infinite duration and stalls.
Behaviors
Config
Feature default is the value a feature's defaultConfig supplies. A behavior's own fallback for a key left unset is described under Doc.
| Key | Type | Feature default | Read by | Doc |
|---|---|---|---|---|
deriveStartMediaTime? |
DeriveStartMediaTime |
— | establishStartMediaTime | The reduce seam (coordination knob). Defaults to deriveSharedMinStartMediaTime. |
gateFirstParse |
GateFirstParse |
gateFirstParseOnAnchor |
resolveAudioTrack, resolveTextTrack, resolveVideoTrack | First-parse placement gate (see primitives/gate-first-parse); absent → parse immediately. |
reschedule |
Reschedule<ResolvedTrack> |
delayedReschedule(mediaPlaylistReloadDelay) |
resolveAudioTrack, resolveTextTrack, resolveVideoTrack | Live media-playlist re-run policy; absent → resolve once. |
resolveLiveLatency? |
ResolveLiveLatency |
resolveLiveLatency |
seekToLiveEdge | Resolve the target live latency (seconds the playhead should trail the live edge) for the timeline-bearing track. Injected by the engine so the latency rule stays format-specific (HLS: HOLD-BACK, default 3× target duration; DASH would read suggestedPresentationDelay) while this behavior stays neutral. Absent → 0 (seek straight to the edge). |
State
| Key | Type | Initial | Declared by | Doc |
|---|---|---|---|---|
mediaContainerData |
Record<string, MediaContainerData> | undefined |
— | establishStartMediaTime | Transient origin-establishment data, keyed by track type ('video' / 'audio') — per spec one init+media pair per type suffices, and ABR rungs of a type share the origin. Filled by the discover steps across appends, reset per source. Never the model — the churn stays here; only the settled startMediaTime reaches Track. |
presentation |
MaybeResolvedPresentation | undefined |
— | syncLiveSeekableRange, seekToLiveEdge, establishStartMediaTime | The presentation being played. A caller writes { url }; resolvePresentation parses the manifest and populates the rest. (documented on resolvePresentation) |
startPosition |
number | undefined |
— | seekToLiveEdge | One-shot start-position command in presentation-timeline seconds. Written here on entry into live; consumed (cleared) by applyStartPosition. |
Context
| Key | Type | Declared by | Doc |
|---|---|---|---|
mediaElement |
HTMLMediaElement | undefined |
seekToLiveEdge | 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) |
mediaSource |
MediaSource | undefined |
syncLiveSeekableRange | The attached MediaSource, published by setupMediaSource — its sole writer — only once it is open, and cleared when the attachment is torn down (source change, sourceclose, destroy). The other MSE behaviors read it. (documented on setupMediaSource) |
Composed by
- @videojs/spf/engines/hls-video
- @videojs/spf/engines/hls-audio
- @videojs/spf/engines/hls-video-mpeg-ts
- @videojs/spf/engines/hls-audio-mpeg-ts
Other functions and constants
| Name | Kind | Description | Source |
|---|---|---|---|
behaviors |
const | The behaviors the feature composes, in setup order. Listed under Behaviors. | src/playback/features/live.ts |
defaultConfig |
const | The config defaults the feature contributes. Its value: { resolveLiveLatency, reschedule: delayedReschedule(mediaPlaylistReloadDelay), gateFirstParse: gateFirstParseOnAnchor }. |
src/playback/features/live.ts |
initialState |
const | The state values the feature seeds. It seeds none ({}). |
src/playback/features/live.ts |
Types
| Name | Kind | Description | Source |
|---|---|---|---|
Behaviors |
type | The type of behaviors. |
src/playback/features/live.ts |
Config |
type | Every config key the behaviors read. Listed under Config. | src/playback/features/live.ts |
Context |
type | Every context key the behaviors declare. Listed under Context. | src/playback/features/live.ts |
State |
type | Every state key the behaviors and external signals declare. Listed under State. | src/playback/features/live.ts |