diff --git a/app/src/main/java/com/vitorpamplona/amethyst/Amethyst.kt b/app/src/main/java/com/vitorpamplona/amethyst/Amethyst.kt index ad21a7f0f..f3dde4d65 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/Amethyst.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/Amethyst.kt @@ -40,6 +40,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import java.io.File import kotlin.time.measureTimedValue @@ -53,7 +54,9 @@ class Amethyst : Application() { val videoCache: VideoCache by lazy { val newCache = VideoCache() - newCache.initFileCache(this) + runBlocking { + newCache.initFileCache(this@Amethyst) + } newCache } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoCache.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoCache.kt index c4db43820..c13aeb560 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoCache.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoCache.kt @@ -27,6 +27,8 @@ import androidx.media3.datasource.cache.CacheDataSource import androidx.media3.datasource.cache.LeastRecentlyUsedCacheEvictor import androidx.media3.datasource.cache.SimpleCache import androidx.media3.datasource.okhttp.OkHttpDataSource +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import okhttp3.OkHttpClient import java.io.File @@ -41,16 +43,17 @@ class VideoCache { lateinit var cacheDataSourceFactory: CacheDataSource.Factory - @Synchronized - fun initFileCache(context: Context) { + suspend fun initFileCache(context: Context) { exoDatabaseProvider = StandaloneDatabaseProvider(context) - simpleCache = - SimpleCache( - File(context.cacheDir, "exoplayer"), - leastRecentlyUsedCacheEvictor, - exoDatabaseProvider, - ) + withContext(Dispatchers.IO) { + simpleCache = + SimpleCache( + File(context.cacheDir, "exoplayer"), + leastRecentlyUsedCacheEvictor, + exoDatabaseProvider, + ) + } } // This method should be called when proxy setting changes.