How to implement oncompletionlistener to detect end of media file in Exoplayer
Exoplayer offer advance implementation which media player do not.
in Advance example of Exoplayer by Android, in FullPlayerActivity.java they have implemented onStateChanged, which offers STATE_ENDED
You can download example from the right hand section of this page under term RELATED SAMPLES
Google has deprecate ExoPlayer.STATE_ENDED
and has replaced with Player.STATE_ENDED
.
Since this post has been a while, I will write a Kotlin
version of the listener down below.
this.simpleExoPlayer?.addListener(object : Player.DefaultEventListener() { override fun onPlayerStateChanged(playWhenReady: Boolean,playbackState: Int) { when (playbackState) { Player.STATE_IDLE -> {} Player.STATE_BUFFERING -> {} Player.STATE_READY -> {} Player.STATE_ENDED -> {} } }})
UPDATE: 05-2020Since DefaultEventListener
and onPlayerStateChanged()
are deprecated.
player.addListener(object : Player.EventListener { override fun onPlaybackStateChanged(state: Int) { if (state == Player.STATE_ENDED) { // your code } }})