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>
5.4 KiB
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 ascalculateDurationFeature; 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 ascurrentTimeFeature; without one, the stream never ends.
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 |
|---|---|---|---|---|
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
- @videojs/spf/engines/hls-video
- @videojs/spf/engines/hls-audio
- @videojs/spf/engines/hls-background-video
- @videojs/spf/engines/hls-video-mpeg-ts
- @videojs/spf/engines/hls-audio-mpeg-ts
- @videojs/spf/engines/hls-background-video-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/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 |