Listen for events with the Wowza Flowplayer Android SDK

With the Wowza Flowplayer Android SDK, you can consume player-emitted events directly with the API. Your Android application can then respond to player status changes in real time, implementing custom logic or updating the user interface in a pre-determined way.

Obtain an API handle

To use the API, you need to have a handle to the flowplayer instance that's hosted by the FlowplayerView class.

For more on this topic, see Create a player instance. The code examples in the FlowplayerSupportFragment and FlowplayerView sections demonstrate how to declare a top-level reference to your player instance in your activity or fragment.

Create an event listener

To make your player listen to playback or player events, you need to create a class that implements the EventListener interface of the respective event. Then you can create an instance of this class and pass it to the player.

Copy
Copied
flowplayer.addEventListener(new MyEventListener())

Event listeners reference

The following table lists events and the listener interfaces that help to capture user interactions with your UI. See the full reference documentation for additional details.

Available events Listener interface
AdBreakCompleteEvent OnAdBreakCompleteListener
AdBreakStartEvent OnAdBreakStartListener
AdClickEvent OnAdClickListener
AdCompleteEvent OnAdCompleteListener
AdErrorEvent OnAdErrorListener
AdPauseEvent OnAdPauseListener
AdResumeEvent OnAdResumeListener
AdSkipEvent OnAdSkipListener
AdStartEvent OnAdStartListener
AudioTrackSelectEvent OnAudioTrackSelectListener
AudioTracksEvent OnAudioTracksListener
BufferEvent OnBufferListener
CompleteEvent OnCompleteListener
DurationChangeEvent OnDurationChangeListener
ErrorEvent OnErrorListener
FullscreenEvent OnFullscreenListener
HaltEvent OnHaltListener
IdleEvent OnIdleListener
LiveEvent OnLiveStateListener
MuteEvent OnMuteListener
PauseEvent OnPauseListener
PlayEvent OnPlayListener
ProgressEvent OnProgressListener
SpeedEvent OnSpeedListener
SubtitleTrackSelectEvent OnSubtitleTrackSelectListener
SubtitleTracksEvent OnSubtitleTracksListener
VideoTrackSelectEvent OnVideoTrackSelectListener
VideoTracksEvent OnVideoTracksListener
VolumeEvent OnVolumeListener

Example: Looping the player

In this example, we create a MyActivity class that inherits from AppCompatActivity and implements the OnCompleteListener interface. Inside the onCreate() method, the activity is initialized so it can listen for events related to the player's completion. The onComplete() method is then called when the player stops playing its content. When the media content finishes playing, the player seeks back to the beginning and starts to play again.

Copy
Copied
class MyActivity : AppCompatActivity, OnCompleteListener {
    // Declare top-level reference to a Flowplayer instance
    lateinit var flowplayer: Flowplayer

    // Initialize the activity
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Obtain playerFragment (from XML or programmatically)
        flowplayer = getPlayerFragment().getPlayer()
        flowplayer.addEventListener(this)
    }

    // Call when the player completes playing content
    override fun onComplete(event: CompleteEvent) {
        // Seek to the start of the content and resume playback
        flowplayer.seek(0)
        flowplayer.play()
    }
}