Checking the Playback state of a player object in tvOS using tvJS

333 Views Asked by At

does anyone know how to correctly check the playback state of a player object? Im trying to build a tvOS application and I need to check when the video has ended. *This app is not native it is build using TVJS. This is what I have right now, but its not working:

if (player.playbackState == "end") {
      console.log("ending")
    }

Thanks again.

1

There are 1 best solutions below

0
On

One possibility: Hook into event stateDidChange

player.addEventListener("stateDidChange", videoPlayer.onStateDidChange);

then check for what you are interested in:

videoPlayer.onStateDidChange: function(stateObj) {
  console.log("onStateDidChange: "+stateObj.oldState+" to "+stateObj.state);

    // states: begin, scanning, loading, paused, playing, end
[...]
}

(with videoPlayer being kind of wrapper around the TVJS player. See https://github.com/iBaa/PlexConnectApp/blob/master/PlexConnectApp/js/VideoPlayer.js for more details.)