ExoPlayer Short Tip 2 : ConcatenatingMediaSource windowIndex change

This is the second instalment of ExoPlayer Short Tip.

A ConcatenatingMediaSource is a concatenation of other MediaSource often referred to simply as a playlist. This will allow the ExoPlayer to play a sequence of media automatically (auto-play).

We find ourselves needing a way to be notified only once each time a new window within a ConcatenatingMediaSource is reached.

We will need what we’ve learned in Tip 1 to cover all cases.

The onNewWindowIndex(index: Int) method will be called by onPrepared() when your media is ready for the first time. The onPositionDiscontinuity() will call onNewWindowIndex(index: Int) when a new window is reached, either automatically or after a seek.