Listen to Player events (Web)
Work with events to capture user interactions with the Player and trigger custom actions.
Listening to events can only be implemented with the Player Embed Script or Player Library Script, not with iFrame embeds.
Find all available events in the Web SDK Reference.
Listen to events
To pick up on events use the method player.on():
player.on(dailymotion.events.YOUR_EVENT, callback) // callback function will be trigger each time 'YOUR_EVENT' is fired
player.on(dailymotion.events.YOUR_EVENT, callback, { once: true }) // callback function will be trigger only the first time 'YOUR_EVENT' is firedExample of adding a listener to the Player event PLAYER_START:
player.on(dailymotion.events.PLAYER_START, (state) => {
console.log("Received PLAYER_START event. Current state is:", state);
});Example of adding a unique listener:
If you want a listener to be invoked only once, pass an additional object composed of {once:true} into the method.
player.on(
dailymotion.events.PLAYER_START,
(state) => {
console.log("Received PLAYER_START event. Current state is:", state);
},
{ once: true }
);Stop listening to an event
To unbind specified listeners, use player.off():
player.off(dailymotion.events.YOUR_EVENT, callback) // the specific callback associated to 'YOUR_EVENT' will be removed
player.off(dailymotion.events.YOUR_EVENT) // every listeners binded to 'YOUR_EVENT' will be removedUpdated 23 days ago
