For a non-concatenated MediaSource (representing any particular media fragment that you want to play), you will receive STATE_ENDED after the media fragment has finished playing.
For ConcatenatingMediaSource, this happens when all concatenation is over (i.e. you played to the end of the last element in concatenation). So STATE_ENDED happens when the entire MediaSource has finished playing.
For ConcatenatingMediaSource, the best callback for determining the end of the current media and the start of the next media playback is "onPositionDiscontinuity" You should use onPositionDiscontinuity () to find out when transitions occur. Note that onPositionDiscontinuity is also called for some other cases, but you can call getCurrentWindowIndex () and compare it with the window you are in to determine if the transition has occurred. You can do something like below:
public void onPositionDiscontinuity() { int newIndex = player.getCurrentWindowIndex(); if (newIndex != currentIndex) {
Note: onPositionDiscontinuity () is not called for the 1st item in the playlist unless we explicitly call player.seekTo (position, 0). Therefore, to process everything that you do to play all the multimedia in the playlist, you must process separately for the 1st item in the playlist.
source share