I searched two days for this question in github but i can\'t find true answer . I want example for detecting pause / resume
in ExoPlayer > 2.x
.
An
Kotlin 2020 solution approach UPDATE
Events such as changes in state and playback errors are reported to registered Player.EventListener
instances.
Player.EventListener
has empty default methods, so you only need to implement the methods you’re interested in.
First your class, say your activity, has te conform to the Player.EventListener
interface.
Then you override the onIsPlayingChanged
method, on the class. Outside onCreate
method...
Add the listener to your player instance:
// Adding player listener for tracking events
player?.addListener(this)
You can check if the player is playing (i.e. the position is advancing) with Player.isPlaying:
//Listening to player events
override fun onIsPlayingChanged(isPlaying: Boolean){
if (isPlaying) {
// Active playback.
} else {
// Not playing because playback is paused, ended, suppressed, or the player
// is buffering, stopped or failed. Check player.getPlaybackState,
// player.getPlayWhenReady, player.getPlaybackError and
// player.getPlaybackSuppressionReason for details.
}
}
That's it. Very simple.