I have referred this link for creating CachedDataSource for Exo-Player and successfully created it, but I am not sure, how to delete the cache of the loaded video?
There is a code example here , but I am not sure how to implement it.Any help will be appreciated.
if you created a cache folder like it described in https://exoplayer.dev/downloading-media.html example for kotlin
@Synchronized
fun getDownloadCache(): Cache {
if (downloadCache == null) {
val downloadContentDirectory = File(getDownloadDirectory(), DOWNLOAD_CONTENT_DIRECTORY)
downloadCache = SimpleCache(downloadContentDirectory, NoOpCacheEvictor(), getDatabaseProvider())
}
return downloadCache as Cache
}
you can simply access this cache anywhere in your code to do this
fun clearCache() {
application.getDownloadCache().release()
}
Or clean single key with this:
fun removeKeyFromCache(key: String) {
CacheUtil.remove(application.getDownloadCache(), key)
}
application is an instance of your app, which can be created like this
lateinit var singleton: MyApp
open class MyApp: Application() {
override fun onCreate() {
super.onCreate()
singleton = this
}
}
And access it from anywhere:
private val application: MyApp = singleton
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With