Skip to the content.

Docs | iOS

Events

The player and some of the plugins fire events that tell the application (and other plugins) about events that occur before/during/after playback.

On this page:

Listening to events from application code

	// add observer to list of different events
	// don't forget to use weak self to prevent retain cycles when needed
	player.addObserver(self, events: [PlayerEvent.playing, PlayerEvent.durationChanged, PlayerEvent.stateChanged]) { [weak self] event in
	     if type(of: event) == PlayerEvent.playing {
	        // handle playing event
	     } else if type(of: event) == PlayerEvent.durationChanged {
	        let duration = event.duration
	     } else if type(of: event) == PlayerEvent.stateChanged {
	        let newState = event.newState
	        let oldState = event.oldState
	     }
	}

Listening to events from plugin code

Plugins can’t call addObserver on the player – instead, an identical function exists on the MessageBus object that is passed to the plugin.

Core Player Events

The Player events are defined in the PlayerEvent class.

Normal Flow

Additional User actions

Track change

Errors

State Change

The Player can be in one of 4 playback states:

idle, buffering, ready, ended

The stateChanged event is fired when the player transitions between states.

Ad Events

Defined in AdEvent class.

Code Samples