事件 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 user initiated play -
pause playback paused -
userpause user initiated pause -
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
quartile playback progress by quartiles 25%, 50%, 75% or 100%
duration changing the duration duration in seconds
seek rewind time in seconds
userseek user initiated 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 -
next move to the next file in the playlist -
previous move to the previous file in the playlist -

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

20.0.0
2024 © PlayerJS

登录

登录

免费注册

注册
注册即表示您同意服务条款
登录(如果您有帐户)

恢复密码

恢复
忘记电子邮件?联系我们