Exoplayer: With v2.12.0 playlist api, how do I know which source causes the onPlayerError

Created on 21 Sep 2020  路  4Comments  路  Source: google/ExoPlayer

[REQUIRED] Searched documentation and issues

Looked at StackOverflow and other issues. Could not find anything related

[REQUIRED] Question

I using the new playlist API provided with v2.12.0 and loading multiple MediaItems into the player. One of the sources throws an ExoPlaybackException of ExoPlaybackException.TYPE_SOURCE type.

How do I know which media item this relates to?

A full bug report captured from the device

No specific bug is referred to.

Link to test content

General question that does not relate to a specific source.

question

Most helpful comment

You can also use AnalyticsListener and listen to onPlayerError which has an EventTime argument with a windowIndex field. This is essentially equivalent to the proposal above, but easier to read in code:

@Override
 public void onPlayerError(EventTime eventTime, ExoPlaybackException e) {
    Log.e("ERROR", "Media item number " + eventTime.windowIndex + " failed.");
 }

All 4 comments

I think in this case the field ExoPlaybackException.mediaPeriodId has a media period id assigned (it is not null). If so you can do something like this:

MediaSource.MediaPeriodId mediaPeriodId = playbackException.mediaPeriodId;
int windowIndex = player.getCurrentTimeline()
   .getPeriodByUid(mediaPeriodId.periodUid, new Timeline.Period()).windowIndex;
player.removeMediaItem(windowIndex);

Please note, that the above assumes that you are having a 1:1 relationship between media items and windows in the timeline. This means you are not using a ConcatenatingMediaSource. In case you are only using the new API with MediaItem you are fine.

Please let me know whether that works for you.

You can also use AnalyticsListener and listen to onPlayerError which has an EventTime argument with a windowIndex field. This is essentially equivalent to the proposal above, but easier to read in code:

@Override
 public void onPlayerError(EventTime eventTime, ExoPlaybackException e) {
    Log.e("ERROR", "Media item number " + eventTime.windowIndex + " failed.");
 }

Thanks a lot for the fast answers, this solves my problem. 馃檪 馃檱

Cool, thanks for letting us know. I'm closing this issue. Please re-open if you think it is needed.

Was this page helpful?
0 / 5 - 0 ratings