androidx / androidx/media

Unexpected behavior after HLS media segment download timeout and switching to a lower variant

Open
#3,362 2 comments 0 reactions 1 assignee View on GitHub

@tianyif is already working on this.

Since Aug 7, 2026.

question
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Version

Media3 1.8.0

Description

We noticed that sometimes at the moment of the variant changing down the presentation timestamps of the samples pushed into the video decoder are repeating.

While investigating this the following 3 issues where found:

  1. Partial samples are not purged from the SampleQueue when a media chunk is excluded (root cause of "PTS going back")
    Potential location of the issue: HlsSampleStreamWrapper.onLoadError.
    Symptom: Renderer PTS goes back and sometimes the decoder is getting stuck

  2. Live playback rewinds live playback to the initial playback position.
    Potential location of the issue: HlsSampleStreamWrapper.onLoadError. pendingResetPositionUs = lastSeekPositionUs inside
    if (isMediaChunk && bytesLoaded == 0)
    Symptom: After a burst of network errors that empties mediaChunks, playback "skips back" by a significant amount (tens of minutes).

  3. the same segment (with the same variant) is being downloaded multiple times.
    Potential location of the issue: HlsChunkSource.getNextChunk, inside the upstream if (shouldForceKeepCurrentTrackSelection) branch.
    Symptom: During bad network conditions same segment URL is downloaded multiple times back to back on the just-blacklisted variant.

Devices that reproduce the issue

This was reproduced on a proprietary Android device, but it does not look like the specific device is important.

Devices that do not reproduce the issue

Not applicable

Reproducible in the demo app?

Not tested

Reproduction steps

1, Play live HLS stream with multiple video variants.

  1. Simulate a network problem that causes at least one video segment load to time out mid-transfer (RequestTimeoutException at ~10 s with bytesLoaded > 0).
Expected result
  • The playback continues and the video sample are queued into the decoder in the correct order of PTSs.
  • Each media segment in a particular variant is loaded only once.
Actual result
  • The PTS values sometimes jump back (sometimes by several seconds and sometimes by multiple minutes).
  • Sometimes the same variant of a specific video segment is downloaded multiple times.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.