Initial commit
This commit is contained in:
commit
21bfbfb139
520 changed files with 47819 additions and 0 deletions
28
app/src/main/java/ani/dantotsu/media/anime/VideoCache.kt
Normal file
28
app/src/main/java/ani/dantotsu/media/anime/VideoCache.kt
Normal file
|
@ -0,0 +1,28 @@
|
|||
package ani.dantotsu.media.anime
|
||||
|
||||
import android.content.Context
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.database.StandaloneDatabaseProvider
|
||||
import androidx.media3.datasource.cache.LeastRecentlyUsedCacheEvictor
|
||||
import androidx.media3.datasource.cache.SimpleCache
|
||||
import java.io.File
|
||||
|
||||
@UnstableApi
|
||||
object VideoCache {
|
||||
private var simpleCache: SimpleCache? = null
|
||||
fun getInstance(context: Context): SimpleCache {
|
||||
val databaseProvider = StandaloneDatabaseProvider(context)
|
||||
if (simpleCache == null)
|
||||
simpleCache = SimpleCache(
|
||||
File(context.cacheDir, "exoplayer").also { it.deleteOnExit() }, // Ensures always fresh file
|
||||
LeastRecentlyUsedCacheEvictor(300L * 1024L * 1024L),
|
||||
databaseProvider
|
||||
)
|
||||
return simpleCache as SimpleCache
|
||||
}
|
||||
|
||||
fun release() {
|
||||
simpleCache?.release()
|
||||
simpleCache = null
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue