I want to determine the video currently playing in the exoplayer is from cache directory or is directly playing from the server.
Asked
Active
Viewed 1,217 times
1 Answers
2
There is no direct check or call back (AFAIK) but you can check yourself for a given URI if it is cached or not, and if it is cached whether it is fully cached or only partially cached.
The getCached method will allow you query this (https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/upstream/cache/CacheUtil.html):
public static void getCached(
DataSpec dataSpec,
Cache cache,
CachingCounters counters)
Its worth remembering that it may not be the whole video that is cached (especially above a certain length) and if not it won't necessarily be the beginning that is cached.
There is a nice example in the answer showing how to see what is cached and what is available here: https://stackoverflow.com/a/48099461/334402

Mick
- 24,231
- 1
- 54
- 120
-
Thanks Mick. But this solution doesnot give me clear identification of how to distinguish between cached video or stream video. – Prakhar Gupta Jul 22 '19 at 10:35
-
@PrakharGupta - I'm not sure you can and even if you could it will not be for a whole stream usually just for part of it. I think a reasonable design goal for most general cases would be to keep the domains well separated - i.e. the player would have the URI and request it but it would not have any visibility of when the URI is being served locally or via the network. For your special case I suspect you may require some mechanism like the one outlined above. – Mick Jul 22 '19 at 12:50