Events JS API


The JavaScript API allows you to get player events, request data and manage it from the outside.

Events   Show commands and requests

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 starts -
userplay playback starts by user -
pause playback paused -
userpause playback paused by user -
stop playback stopping -
end end of playback -
finish end of playback including advertising -
new starting a new file -
time changing the playback time playback time in seconds
duration changing the duration duration in seconds
seek rewind time in seconds
mute mute the sound -
unmute unmute the sound -
volume volume level the volume from 0 to 1
quality quality changed quality name
audiotrack audio track changed the name of the audio track
subtitle subtitles changed subtitles name
speed speed changed speed value
fullscreen full screen mode -
exitfullscreen exit from full screen mode -
buffering start of buffering -
buffered end of buffering -
loaderror load error error description
error playback error error description
fragment HLS chunk name of ts file
height the player height has changed value in px
playlist the playlist loaded -
download the user clicked the download button -
visibility the player's visibility has changed -
resize changed the size of the player in normal mode width, height
geo received a geo data
 
casted
uncasted
Chromecast switching
ui displaying the control panel 0 or 1
click click or tap on the player -
line click or tap on the timeline -

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);
});

19.9.102024 © PlayerJS

Sign up free

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

Restore password

Restore
Forgot email? Contact us