Skip to main content

Listening to Player Events

Event Subscription

The application can subscribe to events such as changes in player state, buffering state, seek state and playback errors.

// Register a callback to be called when a certain player event is published

player.subscribe('error', callback);

Observe Player state changes

Changes in player state can be received by implementing the following

player.subscribe('playbackstatechanged', (state: string) => {
switch (state) {
case 'idle':
//handle idle state.
break;
case 'loading':
//handle loading state.
break;
case 'loaded':
//handle loaded state.
break;
case 'started':
//handle started state.
break;
case 'paused':
//handle paused state.
break;
}
});

The player can be in one of the following playback states:

  • PlaybackState.IDLE: This is the initial state, indicates that the player has no media to play and doesn't hold any resources.
  • PlaybackState.LOADING: Indicates that the player is loading the initial media chunks (manifest, initialization chunks etc.,) required to play the Media Source.
  • PlaybackState.LOADED: Indicates that the player has loaded all the resources needed to start playback rendering.
  • PlaybackState.STARTED: Indicates that the player has started rendering playback.
  • PlaybackState.PAUSED: Indicates that the player has paused rendering playback.

Player Events and State

Player State Machine

Observing the Playback Time

Changes in player progress can be received by implementing the following in a registered listener/delegate:

player.subscribe('progressupdate', function (event) {
// progess update
});

Handle Player Errors

Playback failures can be observed by subscribing to the following in a registered listener/delegate.

player.subscribe('error', callback);
note

Refer to Error Codes page for the full list of possible error codes.