androidx / androidx/media

ExoPlayer ignores cached segments when adaptive streaming selects different quality

Open
#2,518 4 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

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

Description

Version

Media3 1.5.1

More version details

No response

Devices that reproduce the issue

Google Pixel 3a with Android 11

Devices that do not reproduce the issue

not tested

Reproducible in the demo app?

Not tested

Reproduction steps
  1. Set up two ExoPlayer instances:
    Player 0 for playback.
    Player 1 for preloading segments.

  2. Videos are encoded using DASH with multiple representations (e.g., 240p, 480p, 720p). Each video has multiple .m4s segment files and init files per representation.

  3. Use a custom CacheKeyFactory to unify segment keys across quality levels:

override fun buildCacheKey(dataSpec: DataSpec): String {    val url = dataSpec.uri.toString()
    val chunkRegex = Regex(".*/([^/]+)/chunk-stream\\d+-(\\d+)")
    val initRegex = Regex(".*/([^/]+)/init-stream(\\d+)")

    chunkRegex.find(url)?.let {
        val videoId = it.groupValues[1]
        val chunkId = it.groupValues[2]
        return "video-$videoId-chunk-$chunkId"
    }

    initRegex.find(url)?.let {
        val videoId = it.groupValues[1]
        val streamId = it.groupValues[2]
        return "video-$videoId-init-$streamId"
    }
    return url
}
  1. Player 1 preloads the first few segments of video N+1 using this setup and stores them in the SimpleCache.

  2. When the user scrolls, Player 0 plays video N+1 using the same CacheKeyFactory, expecting cache reuse for the first few segments, and then uses ABR to download the missing segments at the end.

Both players download videos based on

val mediaSource = DashMediaSource.Factory(cacheDataSourceFactory)
                .createMediaSource(mediaItem)
            exoPlayer.setMediaSource(mediaSource)

where mediaItem is based on an URL.

Expected result

Player 0 should detect and use the cached segments (from Player 1), even if they are of a different quality than what the adaptive logic would normally choose.

Playback should begin immediately without needing to redownload those segments in a different quality.

Actual result

Player 0 ignores the cached segments if their quality doesn't match the current ABR selection.

If the current ABR selection is not in the cache, it re-downloads the same segment index but in different quality, making the preloaded segments useless despite identical cache keys.

Media

Big Buck Bunny Dataset: https://ftp.itec.aau.at/datasets/DASHDataset2014/BigBuckBunny/4sec/

Bug Report
  • You will email the zip file produced by adb bugreport to android-media-github@google.com after filing this issue.

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.