Skip to content

Fatal IndexOutOfBoundsException thrown when Media3 PreloadManager is enabled #2821

@jasongrife

Description

@jasongrife

Version

Media3 1.8.0

More version details

No response

Devices that reproduce the issue

Any Android device

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

With an .m3u8 manifest file such as this one:

#EXTM3U
#EXT-X-PROGRAM-DATE-TIME:2019-01-01T00:00:00.000Z
#EXT-X-TARGETDURATION:6
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-ENDLIST

Which has missing Segments.

Then in Media3 Exoplayer when you seekToPlaylistItem without preloading enabled, you get an IndexOutOfBoundsException that gets caught and instead of crashing the app, is pushed out to the Player.Listener#onPlayerError

However, with PreloadManager enabled the Media3 Exoplayer code will not catch the IndexOutOfBoundsException and instead the app crashes.

Expected result

The expectation would be that for Preloading enabled, this exception would be caught as well. And then either thrown to Player.Listener#onPlayerError or PreloadManagerListener#onError, or both.

Actual result

Logs for Media3 Exoplayer attemplting to play that .m3u8 with the missing Segments. Showing it gets caught as a Playback error and not a crashing exception:

Playback error
androidx.media3.exoplayer.ExoPlaybackException: Unexpected runtime error
    at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:911)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:248)
    at android.os.Looper.loop(Looper.java:338)
    at android.os.HandlerThread.run(HandlerThread.java:85)
Caused by: java.lang.IndexOutOfBoundsException: index (0) must be less than size (0)
    at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:1372)
    at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:1354)
    at com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:84)
    at androidx.media3.exoplayer.hls.HlsChunkSource.getNextMediaSequenceAndPartIndex(HlsChunkSource.java:910)
    at androidx.media3.exoplayer.hls.HlsChunkSource.createMediaChunkIterators(HlsChunkSource.java:769)
    at androidx.media3.exoplayer.hls.HlsChunkSource.getNextChunk(HlsChunkSource.java:451)
    at androidx.media3.exoplayer.hls.HlsSampleStreamWrapper.continueLoading(HlsSampleStreamWrapper.java:802)
    at androidx.media3.exoplayer.source.CompositeSequenceableLoader$SequenceableLoaderWithTrackTypes.continueLoading(CompositeSequenceableLoader.java:178)
    at androidx.media3.exoplayer.source.CompositeSequenceableLoader.continueLoading(CompositeSequenceableLoader.java:131)
    at androidx.media3.exoplayer.hls.HlsMediaPeriod.continueLoading(HlsMediaPeriod.java:408)
    at androidx.media3.exoplayer.source.MaskingMediaPeriod.continueLoading(MaskingMediaPeriod.java:229)
    at androidx.media3.exoplayer.MediaPeriodHolder.continueLoading(MediaPeriodHolder.java:253)
    at androidx.media3.exoplayer.ExoPlayerImplInternal.maybeContinueLoading(ExoPlayerImplInternal.java:3060)
    at androidx.media3.exoplayer.ExoPlayerImplInternal.handleContinueLoadingRequested(ExoPlayerImplInternal.java:3021)
    at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:740)

Crashing IndexOutOfBoundsException stacktrace, when Preloading is enabled:

E  FATAL EXCEPTION: ExoPlayer:Playback
Process: -----
java.lang.IndexOutOfBoundsException: index (0) must be less than size (0)
    at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:1372)
    at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:1354)
    at com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:84)
    at androidx.media3.exoplayer.hls.HlsChunkSource.getNextMediaSequenceAndPartIndex(HlsChunkSource.java:910)
    at androidx.media3.exoplayer.hls.HlsChunkSource.createMediaChunkIterators(HlsChunkSource.java:769)
    at androidx.media3.exoplayer.hls.HlsChunkSource.getNextChunk(HlsChunkSource.java:451)
    at androidx.media3.exoplayer.hls.HlsSampleStreamWrapper.continueLoading(HlsSampleStreamWrapper.java:802)
    at androidx.media3.exoplayer.source.CompositeSequenceableLoader$SequenceableLoaderWithTrackTypes.continueLoading(CompositeSequenceableLoader.java:178)
    at androidx.media3.exoplayer.source.CompositeSequenceableLoader.continueLoading(CompositeSequenceableLoader.java:131)
    at androidx.media3.exoplayer.hls.HlsMediaPeriod.continueLoading(HlsMediaPeriod.java:408)
    at androidx.media3.exoplayer.source.preload.PreloadMediaPeriod.continueLoading(PreloadMediaPeriod.java:274)
    at androidx.media3.exoplayer.source.preload.PreloadMediaSource$PreloadMediaPeriodCallback.lambda$onContinueLoadingRequested$1$androidx-media3-exoplayer-source-preload-PreloadMediaSource$PreloadMediaPeriodCallback(PreloadMediaSource.java:523)
    at androidx.media3.exoplayer.source.preload.PreloadMediaSource$PreloadMediaPeriodCallback$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
    at android.os.Handler.handleCallback(Handler.java:995)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loopOnce(Looper.java:248)
    at android.os.Looper.loop(Looper.java:338)
    at android.os.HandlerThread.run(HandlerThread.java:85)

Media

index-svtt.m3u8

Response body:
#EXTM3U
#EXT-X-PROGRAM-DATE-TIME:2019-01-01T00:00:00.000Z
#EXT-X-TARGETDURATION:6
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-ENDLIST

Bug Report

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions