Listening to player events

You can listen to various playback and player related events directly with the API.

Obtain API handle

In order to use the API you need to have a handle to the FlowplayerView that implements the Flowplayer interface.

Refer to the player initialization documentation on how to create a player instance.

Create event listener

In order to make your player listen to playback / player events you need to create a class that will implement the EventListener interface of the respective event. Then you create an instance of this class and pass it to the player:

flowplayerView.addEventListener(new MyEventListener())

Available events and their listener interfaces:

  • AdBreakCompleteEvent - OnAdBreakCompleteListener
  • AdBreakStartEvent - OnAdBreakStartListener
  • AdClickEvent- OnAdClickListener
  • AdCompleteEvent - OnAdCompleteListener
  • AdErrorEvent- OnAdErrorListener
  • AdPauseEvent- OnAdPauseListener
  • AdResumeEvent- OnAdResumeListener
  • AdSkipEvent - OnAdSkipListener
  • AdStartEvent - OnAdStartListener
  • BufferEvent - OnBufferListener
  • CompletEvent- OnCompleteListener
  • ErrorEvent - OnErrorListener
  • FullscreenEvent- OnFullscreenListener
  • IdleEvent- OnIdleListener
  • MuteEvent- OnMuteListener
  • PauseEvent - OnPauseListener
  • PlayEvent- OnPlayListener
  • SpeedEvent - OnSpeedListener
  • VolumeEvent - OnVolumeListener

Refer to the API documentation for a full reference.

Example: looping player

In this example we are [inheriting our Activity from FlowplayerFragment](../creating-a-player-instance#use-flowplayer-fragment-or. The activity will then listen to the OnCompleteEvent and seek the player back to the beginning of the video and resume playback.

class MyActivity : FlowplayerFragment, OnCompleteListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Obtain playerFragment (from XML or programmatically)
        // Check the "Creating player instance documentation" for more information
        getPlayerFragment().getPlayer().addEventListener(this)
    }

    override fun onComplete(event: CompleteEvent) {
        // We want to listen to the complete event and seek to beginning to loop the content
        val player = getPlayerFragment().getPlayer()
        player.seek(0) // Seek to beginning
        player.play() // Resume playback
    }
}
Results