While migrating my player from ExoPlayer1 to ExoPlayer2, I have a use case in which I need to set some data specific to the current media (of the playlist), at the start of its playback. After going through ExoPlayer2 docs I found two possible callbacks (event listener of exoPlayer2):
1. Create a sample with ExoPlayerV2.9.+
2. Create ConcatenatingMediaSource with 2 or more media urls
3. Start the player and click "next" button from the available exoPlayer2 controls.
Please have a look at our FAQs about this question. Or look at similar issues which go in a bit more detail (e.g. #4898)
Gone through the FAQs, But for the playlist:
If you are seeking to the next playlist item (that is, click on the next button), you get the discontinuity with reason SEEK. If the next playlist item needs to adjust the position for some reason, you'll get another discontinuity with reason SEEK_ADJUSTMENT because the position changed again.
Thanks for the quick help 馃憤. Now I am moving my track change logic from "onTrackChanged()" to onPositionDiscontinuity().
Just one more query, Will the track change logic keep working correctly with "onTrackChanged()" for Exoplayer version < 2.9.0 ?
onTracksChanged actually had a bug < 2.9.0 because it only reported the one change instead of two. Note that the "tracks" which are changed are unrelated to playlist items. Tracks are specific selections of video, audio and text tracks. If you seek to new playlist item which hasn't been prepared yet, the player briefly transitions to a state without selected tracks and shortly after that it selects tracks for the new item as soon as all required information is available.
@tonihei
on next button click why I am getting below two reason one after another :
reason = Player.DISCONTINUITY_REASON_SEEK
reason = Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT
reason = Player.DISCONTINUITY_REASON_SEEK
also when I seek,
reason = Player.DISCONTINUITY_REASON_SEEK
gets called.
Not sure where should how can I check track changed
@ummerakbar45
_> Not sure where should how can I check track changed_
When playback moves from one item to the next, EventListener.onPositionDiscontinuity will be called with reason = Player.DISCONTINUITY_REASON_PERIOD_TRANSITION
Query the player to determine which item in the playlist is now being played using:
Player.getCurrentWindowIndex and Player.getCurrentTag and the determine if the track gets changed in the playlist.