The player and some of the plugins fire events that tell the application (and other plugins) about events that occur before/during/after playback.
Call the following Player method, one or more times.
eventTypes is the list of events that should be sent to the given listener:
Starting with PlayKit v3.6.2, the addEventListener method returns the listener that was passed to it. This makes it easier to use it with listeners that are defined by anonymous classes, in the case the application wants to remove them later.
There are two methods that allow removing event listeners:
- Remove listener from specific events:
- Remove listener from all events:
player.addEventListener() is only meant to be used by applications. It does not work for plugins. Instead, plugins are given an instance of PlayKit’s MessageBus.
The Player events are defined in the PlayerEvent class.
- SOURCE_SELECTED: Sent when a playback source is selected
- LOADED_METADATA: The media’s metadata has finished loading; all attributes now contain as much useful information as they’re going to.
- DURATION_CHANGE: The metadata has loaded or changed, indicating a change in duration of the media. This is sent, for example, when the media has loaded enough that the duration is known.
- TRACKS_AVAILABLE: Sent when track info is available.
- PLAYBACK_INFO_UPDATED: Sent event that notify about changes in the playback parameters. When bitrate of the video or audio track changes or new media loaded. Holds the PlaybackInfo.java object with relevant data.
- CAN_PLAY: Sent when enough data is available that the media can be played, at least for a couple of frames. This corresponds to the HAVE_ENOUGH_DATA readyState.
- PLAY: Sent when playback of the media starts after having been paused; that is, when playback is resumed after a prior pause event.
- PLAYING: Sent when the media begins to play (either for the first time, after having been paused, or after ending and then restarting).
- PLAYHEAD_UPDATED: Send player position every 100 ms
- ENDED: Sent when playback completes.
- PAUSE: Sent when playback is paused.
- SEEKED: Sent when a seek operation completes.
- SEEKING: Sent when a seek operation begins.
- REPLAY:Sent when replay happened.
- STOPPED: sent when stop player API is called
- VIDEO_TRACK_CHANGED: A video track was selected
- AUDIO_TRACK_CHANGED: An audio track was selected
- TEXT_TRACK_CHANGED: A text track was selected
- VOLUME_CHANGED: Sent when volume is changed.
- METADATA_AVAILABLE: Sent when there is metadata available for this entry.
- ERROR: Sent when an error occurs. The element’s error attribute contains more information. See Error handling for details.
The Player can be in one of 4 playback states:
IDLE, LOADING, READY, BUFFERING
The STATE_CHANGED event is fired when the player transitions between states.
- SUBTITLE_STYLE_CHANGED: Sent when subtitle style is changed
Defined in AdEvent class.