Skip to main content

Listening to Player Events

Observe Player state changes

The application can listen to events from FLPlayer by observing fields on the player node. All the node fields can be observed for change as supported with SceneGraph.

Sample demonstrating playback state change observation
sub initializeFLPlayer()
' consider FLPlayer added in xml UI with id videoPlayer
m.flPlayer = m.top.findNode("videoPlayer")
m.flPlayerState = m.flPlayer.FLPlayerState
m.flPlayerFields = m.flPlayer.FLPlayerFields
m.flPlayerFunctions = m.flPlayer.FLPlayerFunctions

m.flPlayer.observeField(m.flPlayerFields.PLAYBACK_STATE, "onPlaybackStateChanged")
m.flPlayer.observeField(m.flPlayerFields.BUFFERING_STATE, "onBufferingStateChanged")
m.flPlayer.observeField(m.flPlayerFields.SEEKING_STATE, "onSeekingStateChanged")

end sub

sub onPlaybackStateChanged(event as Object)
print "Playback State: "; m.playbackState
end sub

sub onBufferingStateChanged(event as Object)
print "Buffering State: ", event.getData()
end sub

sub onSeekingStateChanged(event as Object)
print "Seeking State: ", event.getData()
end sub

The player can be in one of the following playback states:

  • PlaybackState.IDLE: This is the initial state, indicates that the player has no media to play and doesn't hold any resources.
  • PlaybackState.LOADING: Indicates that the player is loading the initial media chunks (manifest, initialization chunks etc.,) required to play the Media Source.
  • PlaybackState.LOADED: Indicates that the player has loaded all the resources needed to start playback rendering.
  • PlaybackState.PLAYING: Indicates that the player has started rendering playback.
  • PlaybackState.PAUSED: Indicates that the player has paused rendering playback.
  • PlaybackState.STOPPED: Indicates that the player has stopped playback rendering.
  • PlaybackState.FINISHED: Indicates that the player has finished playing content till the end.
  • PlaybackState.ERROR: Indicates that the player has failed with error.

Observing the Playback Time

Changes in player progress can be received by observering CURRENT_TIME field changes.

Observing position and duration change
sub initializeFLPlayer()
...

m.flPlayer.observeField(m.flPlayerFields.CURRENT_TIME, "onPlayheadPositionChanged")
m.flPlayer.observeField(m.flPlayerFields.DURATION, "onContentDurationAvailable")

...
end sub

sub onPlayheadPositionChanged(event as Object)
? "Player Position: ", event.getData()
end sub

sub onContentDurationAvailable(event as Object)
? "Content Duration: ", event.getData()
end sub
note

Duration change is notified only for VOD playback.

Handle Player Errors

Playback failures can be observed on ERROR field changes

Observing Error
sub initializeFLPlayer()
...

m.flPlayer.observeField(m.flPlayerFields.ERROR, "onError")

...
end sub

sub onError(event as Object)
? "Playback Error: ", event.getData()
end sub
note

Refer to Error Codes page for the full list of possible error codes.