androidx / androidx/media

How to properly preload DASH video segments for single ExoPlayer instance with cache fallback?

Open
#2,565 1 comment 0 reactions 1 assignee View on GitHub

@tianyif is already working on this.

Since Jun 27, 2025.

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

Description

Version: 1.8.0
Phone: Google Pixel 3a

I'm using a single ExoPlayer instance inside a RecyclerView.adapter to play a list of DASH video URLs (with manifest files, linking init-segments and regular m4s-segments). Videos can be swiped through (like a TikTok UX). Playback with interactions works, but I’m now trying to improve the seamlessness of the next video by preloading the next 1–2 videos while the current one is playing.

What I’m doing currently:

  • Using SimpleCache and CacheDataSourceFactory with a custom CacheKeyFactory
    
  • Each MediaItem has a setCustomCacheKey(...)
    
  • When a page is selected (onPageSelected), the corresponding DASH video is loaded via a new MediaItem, and played immediately via the same ExoPlayer instance.
    

The idea is to preload the first 10s of the next two videos. The same cache key is used across preloading and playback.

Despite this setup, I see in logging and playback behavior that:

  • The next videos are not served from cache (long download durations, while cache accesses should lead to times under 100ms)
    
  • Initial chunks and init segments are still fetched from network, with visible startup delay
    

What I have tried is using a second ExoPlayer to load segments into a shared cache. However, while doing so, the first ExoPlayer might not be able to fetch the right init-segments for the cached video segments, leading to an error in playback.

How can I properly preload DASH content for a single ExoPlayer instance, such that it:

  • Uses cached segments if available despite their qualities
    
  • Falls back gracefully to ABR if a segment is not fully cached
    
  • Handles the combination of init and video segments and manifests correctly
    
  • Supports quality switching after the preload (not locked to single bitrate)
    

I have seen in the demo that the PreloadManager is used for the player pool. Is there a way to make use of ExoPlayer’s PreloadManager (like in the demo app) even when I’m not using a player pool, but rather a single player?

I have uploaded my used code as a .txt file. Thanks in advance!

githubfile.txt

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.