Skip to content

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

Open
@mnsh222

Description

@mnsh222

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions