ExoPlayer ignores cached data when cached track differs from selected playback track
I'm downloading the first 10 seconds of a video to disk cache using DashDownloader or HlsDownloader. For example, if I force download the lowest quality (144p), then during playback the TrackSelection may choose a different quality track, which is not present in the cache. As a result, the cache is ignored, and the player tries to fetch data from the network. If the network is unavailable, playback fails.
I reproduced this case in the demo-shortform app on the main branch: Changed the test video URL from MP4 to DASH. Configured the playback TrackSelection to prefer high quality. Configured the download TrackSelection to download low quality. The video downloaded successfully, but after disabling the network, playback failed.
Is there a way to force ExoPlayer to play video from cache when cached data exists, no matter which track was cached. and continue to support ABR?
See docs here: https://developer.android.com/media/media3/exoplayer/downloading-media#dl-play-adaptive-streams
In particular:
When building the
MediaItem,MediaItem.localConfiguration.streamKeysmust be set to match those in theDownloadRequestso that the player only tries to play the subset of tracks that have been downloaded. UsingDownload.request.toMediaItemandDownloadRequest.toMediaItemto build theMediaItemwill take care of this for you.
@icbaker Thank you for your reply. When using stream keys, all the benefits of adaptive bitrate (ABR) are lost. In the case of a partial download, I need the player to play only the cached segment (10 seconds) from the cache, and then continue playback using ABR