The player event system uses an event target-like API to register, unregister and dispatch events. The event’s main purpose is to notify the player components about changes to the player state, ads, video progress, etc.
Player core events consist of two event types:
<video>
element. The player runs on top of the HTML video element, which may trigger the events. Information about these types of events can be found here.A core event enum can be access in the following way:
player.Event.Core.EVENT_NAME;
The full core events list can be found here.
Player UI events are events which triggers due to user interaction with the player UI.
A UI event enum can be access in the following way:
player.Event.UI.EVENT_NAME;
The full UI events list can be found here.
You can listen to player events by adding an event listener to the player object, for example:
player.addEventListener(player.Event.Core.TRACKS_CHANGED, event => {
const payload = event.payload;
// Do something with the payload
});
To dispatch an event from the player instance, type the following code:
player.dispatchEvent(
new FakeEvent('myCustomEventName', {
myCustomPayloadProp1: 'Hello',
myCustomPayloadProp2: 'World'
})
);
player.dispatchEvent(new FakeEvent(player.Event.Core.SEEKED));
The player ready promise indicates the that player has done loading the media and can start playing. The promise is resolved when the TRACKS_CHANGED
event is dispatched.
A basic usage of this feature looks like this:
player.ready().then(() => {
var tracks = player.getTracks();
});