useMediaContext
The useMediaContext
hook lets you build custom components which interact directly with the media state store.
The useStore
hook is from
zustand
,
and inherits all of the documentation for Zustand stores.
Features
- Flexible interaction with the player state store
- Based on Zustand’s
useStore
hooks
Anatomy
Import the components and piece the parts together.
State
The useMediaContext
hook returns a Zustand store, which contains the
PlayerState
.
aria
The ARIA text for the current state, providing accessible descriptions for media control actions.
buffered
Current buffered end time for the media in seconds.
bufferedPercent
Current buffered percent of the media, from 0 to 1.
canPlay
Indicates if the media has loaded sufficiently and can be played.
currentSource
The current source that is playing.
currentUrl
The final playback URL for the media that is playing, after any redirects.
duration
Current total duration of the media in seconds.
error
If the media has experienced an error, this property provides details.
errorCount
The number of consecutive errors that have occurred during the media playback, without resolution.
stalled
Indicates if the media playback is currently stalled.
fullscreen
Indicates if the media is being played in fullscreen mode.
hasPlayed
Indicates if the media has been played yet.
hidden
Indicates if all controls are currently hidden.
live
Indicates if the content is live media.
loading
Indicates if the media is currently loading.
mounted
Indicates if the video element is mounted on the DOM. This is used for initialization logic.
playbackRate
The current playback rate for the media. Defaults to 1. constant
means playing
WebRTC playback at a constant pace and not speeding up.
pictureInPicture
Indicates if the media is in picture in picture mode.
poster
The poster image URL for the media. Any thumbnails are automatically parsed from
the input Src[]
.
progress
Current progress of the media in seconds.
playing
Indicates if the media is currently trying to play or paused.
sortedSources
The sorted sources that were passed into the Player. These are the playback sources which will be tried, in order (e.g. WebRTC with a fallback to HLS).
volume
Current volume of the media. 0 if it is muted.
waiting
Indicates if the media is currently waiting for data.
videoQuality
The quality of the video playback.
ended
Indicates if the media playback has ended.
__controlsFunctions
An object containing functions to manipulate the media’s state, such as toggling play/pause, seeking, and changing volume.
These functions are internal - please refer to the UI Kit source code before interacting with these functions.
__device
Information about the device’s capabilities and support for media features. This is an internal object used by Player/Broadcast, but can be used for detecting device capabilities.
__controls
Represents the state of various media control actions, such as play/pause and fullscreen changes. This is an internal object used by Player/Broadcast.
__initialProps
The initial properties passed into the media component. This is an internal object used by Player/Broadcast.
__metadata
Metadata related to the media, such as buffer window and frame rate. This is an internal object used by Player/Broadcast.