google / google/ExoPlayer

Concurrent download and cache

Open
#8,645 14 comments 4 reactions 1 assignee Claimed by @marcbaechinger View on GitHub
enhancement
Dominant language
Java
Stars
21.9k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

### Use case description
I think currently ExoPlayer doesn't handle concurrent downloading and caching in an efficient way.

There are important differences between downloading a file and caching it while it is being played:
- In download, the file needs to be fetched from the network as fast as possible and be stored permanently in storage. No eviction should be done on the downloaded files unless the user intend to delete them.
- In caching while the file is playing from network, fetching should be done as slow as possible in a way that playback won't stall. The fetched data is stored in a cache with limited size that is subject to some eviction strategy, e.g. LRU.

Now if we need to have download and caching support in an app, it isn't trivial how to do it efficiently:
- Download and cache shouldn't interfere each other. Starting a download while a file is being played shouldn't block playing and caching. Similarly starting a play while a file is being downloaded should be done as fast as possible.
- Ideally, not a single byte of the file should be fetched from network twice.
- When the download is complete, in case the file is also stored in LRU cache it should be removed, or it should be easy for the application to remove it from cache as soon as possible, even during the playback.

### Proposed solution
I don't know how to implement this feature with minimum changes. Probably new types of DataSource/MediaSource are required, maybe some that can switch between cache and dowloaded file during the playback. Also maybe Cache interface should be extended.

Again, I don't think it is a feature that is easy to implement in ExoPlayer core for future releases or by extending the current API.
In case there already is a solution, it would be great if you add it to the documentation.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.