Events

Capturing SMARTPLAYER events

You can capture events generated by the smartplayer to perform specific actions based on the state and progress of video playback. To capture these events it will be necessary to use an eventListener, but first let us show you how to implement them in your iframe:

<iframe
        src="https://player.scaleup.com.br/embed/510c42b9fde8af543194ea9fdc0296149cc5a1a5?events=controlsdisabled,controlsenabled,dispose,durationchange,ended,enterFullWindow,enterpictureinpicture,error,exitFullWindow,firstplay,fullscreenchange,leavepictureinpicture,loadedmetadata,loadstart,pause,play,playerreset,playerresize,playing,posterchange,progress,ratechange,ready,resize,seeked,seeking,textdata,timeupdate,useractive,userinactive,volumechange,waiting"
        allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
        allowfullscreen=""
        style="width: 100%; aspect-ratio: 16 / 9; border: 0px; margin: 0px auto"></iframe>

After declaring them, we need to capture and implement in our service:

window.addEventListener('message', event => {  
  const message = event.data;

	switch (message.eventName) {  
    case 'dispose':  
      return console.log('Player disposed');  
    case 'playing':  
      return console.log('Player is playing');  
    case 'waiting':  
      return console.log('Player is waiting');  
    case 'pause':  
      return console.log('Player is paused');  
    case 'ended':  
      return console.log('Player stopped playing');  
    case 'progress':  
      return console.log('Player''s Buffer: ' + message.percentage + '%');  
    case 'timeupdate':  
      return console.log('Time: ' + message.currentTime + '| Video duration: ' + message.duration + '| Video''s percentage: ' + message.percentage + '%');
    case 'questionResponse':
      return console.log('Question answered: ' + message.questionIndex + '| Response: ' + message.response + '| Right answer: ' + message.isCorrect);
    case 'summaryChange':
      return console.log('Is summary: ' + message.isSummary);
  }  
});

This is the result in the browser console:

[Log] Player's Buffer: 9% (x2)  
[Log] Time: 9.975009531014969 (x2) | Video duration: 100 | Video's percentage: 9%
[Log] Time: 10.144443072655653 (x2) | Video duration: 100 | Video's percentage: 10%
[Log] Player is paused (x2)  
[Log] Player's Buffer: 10% (x4)  
[Log] Player is playing (x2)
[Log] Question answered: 1 | Response: c | Right answer: false
[Log] Is summary: true

Available events

EventDescription
controlsdisabledFired when the video player controls are disabled.
controlsenabledFired when the video player controls are enabled.
disposeFired when the video player is removed or destroyed.
durationchangeFired when the video duration is changed.
endedFired when the video reaches its end (when playback is completed).
enterFullWindowFired when the video player enters full window mode.
enterpictureinpictureFired when the video player enters Picture-in-Picture mode.
errorFired when an error occurs during video playback.
exitFullWindowFired when the video player exits full window mode.
firstplayFired when the video is played for the first time.
fullscreenchangeFired when the full-screen state of the video player changes.
leavepictureinpictureFired when the video player exits Picture-in-Picture mode.
loadedmetadataFired when the video metadata is loaded.
loadstartFired when the video loading starts.
pauseFired when the video playback is paused.
playFired when the video playback starts.
playerresetFired when the video player is reset to its original state.
playerresizeFired when the video player is resized.
playingFired when the video is being played.
posterchangeFired when the video poster image (preview image) is changed.
progressFired during video loading, contains: currentTime, duration and percentage.
questionResponseFired when user answers the quiz, contains: questionIndex, response, isCorrect.
ratechangeFired when the video playback rate is changed.
readyFired when the video player is ready to play the video.
resizeFired when the video player is resized.
seekedFired when the video playback moves to a new time point.
seekingFired when the video playback is seeking to a new time point.
summaryChangeFired when the video swaps between summary video and normal version, contains: isSummary.
textdataFired when the video's text data (subtitles or additional information) is available.
timeupdateFired when the video playback time is updated, contains: currentTime, duration and percentage.
useractiveFired when the user is active and interacts with the video player.
userinactiveFired when the user is inactive and does not interact with the video player.
volumechangeFired when the video volume level is changed.
waitingFired when the video is paused, waiting for more data to be loaded.