I\'m looking for any example of implementing cache in ExoPlayer.
ExoPlayer has in its library different classes concerning cache and Google explain in this video th
To resolve the problem of multiple videos or processes trying to access the same cache, you need a true Singleton. A reliable way would be to do it this way:
object VideoCache {
private var sDownloadCache: SimpleCache? = null
private const val maxCacheSize: Long = 100 * 1024 * 1024
fun getInstance(context: Context): SimpleCache {
val evictor = LeastRecentlyUsedCacheEvictor(maxCacheSize)
if (sDownloadCache == null) sDownloadCache = SimpleCache(File(context.cacheDir, "koko-media"), evictor)
return sDownloadCache as SimpleCache
}
}
which you can now use:
private val simpleCache: SimpleCache by lazy {
VideoCache.getInstance(context)
}