Event-related Methods

Have more questions? Submit a request

Event-related Methods

These event-related methods are available on the Player interface instance:

on

The ‘on’ method allows to attach a handler function to a desired event. (The events specifications can be found under the Events topic.)

  • apiInterface.on( eventName, handler ) 
  • eventName 
      • Type: String
      • Value: ‘player.ready’, ‘player.started’, ‘click’, ‘adstartreq’, ‘adstart’ ,’adcomplete’, ‘adpause’,  ‘adplay’, ‘aderror’, ‘content.started’, ‘content.paused’, ‘content.resumed’, ‘content.completed’,  ‘closed’, ‘player.finished’, ‘player.paused’, ‘player.resumed’, ‘player.adpaused’, ‘player.durationChange’ 
  • handler 
      • Type: Function(Object eventObject)
      • A function to execute when the event is triggered

Every eventObject contains following properties:

  • name 
  • Type: String 
    • Value: An event name; namely, ‘ready’, ‘click’, ‘adstart’ ,’adcomplete’, ‘adpause’,  or ‘adplay’
  • player 
  • Type: apiInterface 
    • Player interface instance that triggered an event
  • data 
  • Type: Object 
    • Event specific data

Sample usage:

apiInterface.on('ready', function(eventObject){ alert(“player is ready”)});
// eventObject usage in console new message that event has come with its data
       apiInterface.on('ad.start', handlePlayerEvents);
       apiInterface.on('ad.complete', handlePlayerEvents);

       function handlePlayerEvents(eventObject) {
         console.log("got " + eventObject.name + " event, data: ", eventObject.data);
       } 

off

The ‘off’ method allows to remove a handler function from a desired event handler. (The events specifications can be found under the Events topic.)

  • apiInterface.off( eventName, handler )
    • eventName
      • Type: String
      • Value:  ‘player.ready’, ‘player.started’, ‘click’, ‘adstartreq’, ‘adstart’ ,’adcomplete’, ‘adpause’,  ‘adplay’, ‘aderror’, ‘content.started’, ‘content.paused’, ‘content.resumed’, ‘content.completed’,  ‘closed’, ‘player.finished’, ‘player.paused’, ‘player.resumed’, ‘player.adpaused’, ‘player.durationChange’
    • handler
      • Type: Function(Object eventObject)
      • A handler function previously attached to the event using the on() method

Sample usage:

apiInterface.off(‘click’, previouslyAttachedEventHandlerFunction);

Related articles

Was this article helpful?
0 out of 0 found this helpful