Events tracking


JS API allows you to receive events, request data and manage it from the outside.

Enable subscription in the builder Plugins > API > Events tracking

By default, all events will come to the function PlayerjsEvents (you can change the functions name in the settings) with three arguments:

event event name
id player ID
data information data

function PlayerjsEvents(event,id,data){
   if(event=="play"){
      alert(event);
   }
   if(event == "time"){
      console.log(event,id,data);
   }
}

You can split the subscription into several functions. To do this, specify the object instead function name

{"play":"onPlay","other":"onOther"}

In this example, the play event will come to the onPlay function, and all other events will come to onOther. With PRO you can also add event listeners.

Event Description Returning data
init initialization -
start first playback launching -
play playback starting -
pause playback pausing -
stop playback stopping -
end the end of playback -
new launching new source -
time playback time changed time in seconds
duration playback duration changed duration in seconds
seek seeking time in seconds
mute sound is muted -
unmute sound is unmuted -
volume volume is changed volume from 0 to 1 
quality quality is changed name of the current quality
audiotrack audio track is changed name of the current audio track
subtitle subtitle is turned on name of the current subtitle
fullscreen full screen is turned on -
exitfullscreen exit from the full screen mode -
error playback error error description
fragment HLS fragment name of the current fragment
height the height of the player has changed value in pixels
playlist playlist loaded -
visibility visibility of the player is changed -

Listeners

You can also catch events with listeners (in this case events will not come to PlayerjsEvents). Enable this mode in API options Use listeners

document.getElementById("player").addEventListener("play",onPlay);

How to listen events of the player, which is located in the iframe

Firstly enable the option  Plugins / API / postMessage for iframe. Events will arrive to the window via message event with a data object.

window.addEventListener("message", function (event) {
   console.log(event.data);
});

More: Commands for managing the player and requests for data retrieval




2018 © PlayerJS

Login

Restore password
Sign up
Log in

Sign up free

Sign up
By signing up, you agree to Terms of Service
Login if you have an account

Enterprise

Your name
Website
Email
Phone
Description
Order player

Restore password

Restore
Forgot email? Contact us