Skip to content
giannif edited this page Dec 16, 2014 · 1 revision

Events can be added to a player object with on, and removed with off. There is also a once method, that will only fire once.

For a list of events see the docs.

player.on("stateChange",function(event){
    // event.data is the state
});
player.on("stateChange:playing",function(event){
    // some events support filtering. 
});
player.once("playheadUpdate:20",function(event){
    // this works like a cue point, firing at 20 seconds, but only one time since `once` was used.
});
player.one("playheadUpdate:20",function(event){
    // the one method only fires once.
});

The callback's argument has the following three properties:

  • type: The type of event
  • target: The player that dispatched the event
  • data: An optional property that contains data about the event.

An events object can also be passed into the constructor, or defined on PJS.defaultEvents.

var events = {
    mediaStart:function(event){
      // event.target equals the player that dispatched the event.
    },
    metadata:function(event){
        // event.data is the metadata or other data depending on the event.
    }
};
var player = new PJS.Player($(".videoPlayer")[0], {uri:12345}, events);
Clone this wiki locally