addEventListener
method
Description
Add an event listener to trigger a callback as it happens. The callback will have the event payload as a single argument.
The WaspHlsPlayer
API is heavily event-based.
As an example: to know when a content is loaded, the most straightforward way
is to add an event listener for the "playerStateChange"
event.
This can be done only through this method.
To have the complete list of player events, consult the Player events page.
For example, to listen to errors, you could write:
player.addEventListener("error", function (err) {
console.log(`The player stopped with an error: ${err.message}`);
});
Syntax
player.addEventListener(event, callback);
-
arguments:
-
event
string
: The wanted event’s name. -
callback
Function
: The callback for the event. The same callback may be used again when callingremoveEventListener
.
-