Overview
The phase system is the complete ordered lifecycle of a player instance, a small closed set of stable states from idle to disposed.
Phases do not enumerate event names; they capture coarse playback state.
phase()
Current fine-grained player phase.
Returns: PlayerPhase
| Phase | Entered via | Exits to |
|---|---|---|
idle | constructor | setup via setup(config) |
setup | setup(config) — config resolving, plugins registering, auth/streams/playlist mounting | ready when ready event fires |
ready | ready event fires / load() completes | loading via load(item) |
loading | load(item) — backend pulling source | ready when loaded |
starting | play() / load-play-next / load-play | playing on firstFrame |
playing | firstFrame | buffering, seeking, paused, ended, stopped |
buffering | network stall during playback | playing when buffer refills |
seeking | seek operation | playing when seek completes |
paused | pause() | starting via play() |
ended | natural end of media | starting via load / play / next |
stopped | explicit stop() | starting via load / play |
disposing | dispose() from any phase | disposed |
disposed | disposing completes | terminal — no further transitions |
Emits: phase with { from, to } on every transition.
player.on('phase', ({ from, to }) => {
console.log(`${from} → ${to}`);
});
if (player.phase() === 'playing') {
// safe to call transport methods
}
setupState()
Coarser than phase(), answers “is the player usable right now?”.
| Phase(s) | Return value |
|---|---|
idle | SetupState.NOT_SETUP |
setup | SetupState.SETTING_UP |
disposing, disposed | SetupState.DISPOSED |
| everything else | SetupState.READY |
Returns: SetupState enum value
dispatching()
Names of all events currently being dispatched, innermost last. Empty when no event is dispatching.
Returns: ReadonlyArray<string>
Use this to detect “am I currently inside a beforePlay handler”:
player.on('beforeMutation', (evt) => {
const stack = player.dispatching();
if (stack.includes('beforeSeek')) {
// mutation called from inside a beforeSeek listener
}
});
pushDispatch(name) / popDispatch()
Internal helpers that maintain the dispatch stack.
Called by runDispatchBefore around every before* event.
Plugin authors building custom before-events call these to keep the stack accurate.
| Method | Returns |
|---|---|
pushDispatch(name: string) | void |
popDispatch() | string | undefined |
platform()
The active platform bundle.
Returns browserPlatform even before setup() so early reads don’t need a null check.
Returns: IPlatform
See also
- setup(), pipeline stages and
ready() - Player State,
bufferState,networkState,visibilityState - Events Reference,
phaseevent