Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement oncompletionlistener to detect end of media file in Exoplayer

I am trying to play videos in the form of a playlist one after the other. I am using android Exoplayer to play my files, but there are no listeners in mediaplayer to listen to an end of the media file. Is there a way to listen to the end of media file using exoplayer.

like image 581
user2949215 Avatar asked Dec 08 '14 05:12

user2949215


People also ask

How do you add a listener to ExoPlayer?

You can do this: playerExo. addListener(new ExoPlayer. Listener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { switch(playbackState) { case ExoPlayer.

How do I know if ExoPlayer is playing?

You can use exoplayer. getPlayWhenReady() to check whether the player is currently in a pause state or playing state.

Does YouTube use ExoPlayer?

ExoPlayer is an app-level media player built on top of low-level media APIs in Android. It is an open source project used by Google apps, including YouTube and Google TV.


2 Answers

I know this is old, but just to expand on the accepted answer:

exoPlayer.addListener(this);  .....  @Override public void onPlayerStateChanged(boolean playWhenReady, int state) {      if (state == ExoPlayer.STATE_ENDED){         //player back ended     } } 
like image 75
Joe Maher Avatar answered Sep 17 '22 14:09

Joe Maher


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

like image 36
Murtaza Khursheed Hussain Avatar answered Sep 18 '22 14:09

Murtaza Khursheed Hussain