Files
video.js-mirror/packages/spf/docs/reference/features/media-source.md

5.4 KiB

@videojs/spf/features/media-source

Source: src/playback/features/media-source.ts

mediaSourceFeature

Plays through Media Source Extensions: attaches a MediaSource to the media element, keeps its duration current, and ends the stream once every composed track type has loaded its last segment.

Requires:

  • A writer of presentation.duration, such as calculateDurationFeature; without one, the MediaSource keeps its default duration, and a live stream never gets its infinite duration and stalls.
  • A writer of state.currentTime, such as currentTimeFeature; without one, the stream never ends.

Behaviors

  1. setupMediaSource
  2. updateMediaSourceDuration
  3. endOfStream

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
attachMediaSource? ((mediaSource: MediaSource, mediaElement: HTMLMediaElement) => AttachMediaSourceResult) — setupMediaSource Attach strategy — a composition-supplied implementation. Defaults to attachMediaSource (object URL on the src attribute). Compositions that pair MSE with sibling <source> alternatives wire attachMediaSourceAsSourceElement (e.g. the HLS engine, for setupAirPlay's native fallback source).

State

Key Type Initial Declared by Doc
currentTime number | undefined — endOfStream Current playback position in seconds. Defaults to 0 when undefined. (documented on loadVideoSegments)
presentation MaybeResolvedPresentation | undefined — setupMediaSource, updateMediaSourceDuration, endOfStream The presentation being played. A caller writes { url }; resolvePresentation parses the manifest and populates the rest. (documented on resolvePresentation)

Context

Key Type Declared by Doc
mediaElement HTMLMediaElement | undefined setupMediaSource 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.
mediaSource MediaSource | undefined setupMediaSource, updateMediaSourceDuration, endOfStream 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.

Composed by

Other functions and constants

Name Kind Description Source
behaviors const The behaviors the feature composes, in setup order. Listed under Behaviors. src/playback/features/media-source.ts
defaultConfig const The config defaults the feature contributes. It contributes none ({}). src/playback/features/media-source.ts
initialState const The state values the feature seeds. It seeds none ({}). src/playback/features/media-source.ts

Types

Name Kind Description Source
Behaviors type The type of behaviors. src/playback/features/media-source.ts
Config type Every config key the behaviors read. Listed under Config. src/playback/features/media-source.ts
Context type Every context key the behaviors declare. Listed under Context. src/playback/features/media-source.ts
State type Every state key the behaviors and external signals declare. Listed under State. src/playback/features/media-source.ts