How to configure the use of listeners
HISPlayer SDK supports two ways for setting up the listeners for the events emitted by the classes: AdManager, HisPlayer, MultiView and UIManager.
listenToAllEvents
This method allows to listen to all the events emitted by the class.
const player = new hisplayer.HisPlayer();
player.listenToAllEvents(function (event) {
const eventName = event.type;
// Do something
});
...
player.init({...});
addEventListener and removeEventListener
These methods allow to listen to a specific event emitted by the class and stop listening to it.
const player = new hisplayer.HisPlayer();
const eventHandler = function () {
// Do something
};
player.addEventListener(player.HisPlayerEvent.UIMANAGER_READY, eventHandler);
...
player.init({...});
...
player.removeEventListener(player.HisPlayerEvent.UIMANAGER_READY, eventHandler);
Listen to the ADMANAGER_READY event to know when the ad manager is ready to be used and then listen to any other ad event
player.addEventListener(player.HisPlayerEvent.ADMANAGER_READY, function () {
const adManager = player.getAdManager();
// Listen to the any other ad event once the ADMANAGER_READY is fired
adManager.addEventListener(adManager.AdEventType.AD_STARTED, (event) => {
// Do something
});
});
Listen to the UIMANAGER_READY event to know when the UI manager is ready to be used and then listen to any other UI event
player.addEventListener(player.HisPlayerEvent.UIMANAGER_READY, function () {
const uiManager = player.getUiManager();
// Listen to the any other UI event once the UIMANAGER_READY is fired
uiManager.addEventListener(uiManager.UiEventType.UI_PAUSED, (event) => {
// Do something
});
});