mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 12:02:45 +02:00
Merges VideoCache initialization with get methods
This commit is contained in:
@@ -16,7 +16,7 @@ class PlaybackService : MediaSessionService() {
|
|||||||
MultiPlayerPlaybackManager(HlsMediaSource.Factory(OkHttpDataSource.Factory(HttpClient.getHttpClient())))
|
MultiPlayerPlaybackManager(HlsMediaSource.Factory(OkHttpDataSource.Factory(HttpClient.getHttpClient())))
|
||||||
}
|
}
|
||||||
private val managerProgressive by lazy {
|
private val managerProgressive by lazy {
|
||||||
MultiPlayerPlaybackManager(ProgressiveMediaSource.Factory(VideoCache.get()))
|
MultiPlayerPlaybackManager(ProgressiveMediaSource.Factory(VideoCache.get(applicationContext)))
|
||||||
}
|
}
|
||||||
private val managerLocal by lazy {
|
private val managerLocal by lazy {
|
||||||
MultiPlayerPlaybackManager()
|
MultiPlayerPlaybackManager()
|
||||||
@@ -27,13 +27,8 @@ class PlaybackService : MediaSessionService() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
// Initializes video cache.
|
|
||||||
VideoCache.init(applicationContext)
|
|
||||||
|
|
||||||
setMediaNotificationProvider(
|
setMediaNotificationProvider(
|
||||||
DefaultMediaNotificationProvider.Builder(applicationContext)
|
DefaultMediaNotificationProvider.Builder(applicationContext).build()
|
||||||
// .setNotificationIdProvider { session -> session.id.hashCode() }
|
|
||||||
.build()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,33 +22,33 @@ import com.vitorpamplona.amethyst.service.HttpClient
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||||
fun init(context: Context) {
|
private fun init(context: Context) {
|
||||||
if (!this::simpleCache.isInitialized) {
|
exoDatabaseProvider = StandaloneDatabaseProvider(context)
|
||||||
exoDatabaseProvider = StandaloneDatabaseProvider(context)
|
|
||||||
|
|
||||||
simpleCache = SimpleCache(
|
simpleCache = SimpleCache(
|
||||||
context.cacheDir,
|
context.cacheDir,
|
||||||
leastRecentlyUsedCacheEvictor,
|
leastRecentlyUsedCacheEvictor,
|
||||||
exoDatabaseProvider
|
exoDatabaseProvider
|
||||||
)
|
)
|
||||||
|
|
||||||
cacheDataSourceFactory = CacheDataSource.Factory()
|
renewCacheFactory()
|
||||||
.setCache(simpleCache)
|
|
||||||
.setUpstreamDataSourceFactory(
|
|
||||||
OkHttpDataSource.Factory(HttpClient.getHttpClient())
|
|
||||||
)
|
|
||||||
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
|
|
||||||
} else {
|
|
||||||
cacheDataSourceFactory = CacheDataSource.Factory()
|
|
||||||
.setCache(simpleCache)
|
|
||||||
.setUpstreamDataSourceFactory(
|
|
||||||
OkHttpDataSource.Factory(HttpClient.getHttpClient())
|
|
||||||
)
|
|
||||||
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(): CacheDataSource.Factory {
|
// This method should be called when proxy setting changes.
|
||||||
|
fun renewCacheFactory() {
|
||||||
|
cacheDataSourceFactory = CacheDataSource.Factory()
|
||||||
|
.setCache(simpleCache)
|
||||||
|
.setUpstreamDataSourceFactory(
|
||||||
|
OkHttpDataSource.Factory(HttpClient.getHttpClient())
|
||||||
|
)
|
||||||
|
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun get(context: Context): CacheDataSource.Factory {
|
||||||
|
if (!this::simpleCache.isInitialized) {
|
||||||
|
init(context)
|
||||||
|
}
|
||||||
|
|
||||||
return cacheDataSourceFactory
|
return cacheDataSourceFactory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user