mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-29 17:49:03 +03:00
fix some SimpleCache
issues
This commit is contained in:
parent
cc0646d529
commit
81d158a860
1 changed files with 27 additions and 15 deletions
|
@ -101,7 +101,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
private lateinit var dataSourceFactory: DataSource.Factory
|
private lateinit var dataSourceFactory: DataSource.Factory
|
||||||
private lateinit var dbProvider: StandaloneDatabaseProvider
|
private lateinit var dbProvider: StandaloneDatabaseProvider
|
||||||
private val cacheSize = 100L * 1024L * 1024L // 100 MB
|
private val cacheSize = 100L * 1024L * 1024L // 100 MB
|
||||||
private lateinit var simpleCache: SimpleCache
|
private var simpleCache: SimpleCache? = null
|
||||||
private lateinit var cacheFactory: CacheDataSource.Factory
|
private lateinit var cacheFactory: CacheDataSource.Factory
|
||||||
private lateinit var mediaSourceFactory: MediaSourceFactory
|
private lateinit var mediaSourceFactory: MediaSourceFactory
|
||||||
private lateinit var playerView: DoubleTapPlayerView
|
private lateinit var playerView: DoubleTapPlayerView
|
||||||
|
@ -200,11 +200,15 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
exoPlayer = newPlayer()
|
exoPlayer = newPlayer()
|
||||||
dbProvider = StandaloneDatabaseProvider(baseContext)
|
dbProvider = StandaloneDatabaseProvider(baseContext)
|
||||||
val cacheFolder = File(baseContext.filesDir, "media")
|
val cacheFolder = File(baseContext.filesDir, "media")
|
||||||
simpleCache = SimpleCache(
|
simpleCache = if (SimpleCache.isCacheFolderLocked(cacheFolder)) {
|
||||||
cacheFolder,
|
null
|
||||||
LeastRecentlyUsedCacheEvictor(cacheSize),
|
} else {
|
||||||
dbProvider
|
SimpleCache(
|
||||||
)
|
cacheFolder,
|
||||||
|
LeastRecentlyUsedCacheEvictor(cacheSize),
|
||||||
|
dbProvider
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
initPlayer()
|
initPlayer()
|
||||||
}
|
}
|
||||||
|
@ -234,11 +238,15 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
dataSourceFactory = newDataSourceFactory()
|
dataSourceFactory = newDataSourceFactory()
|
||||||
}
|
}
|
||||||
logcat(LogPriority.INFO) { "playing $uri" }
|
logcat(LogPriority.INFO) { "playing $uri" }
|
||||||
cacheFactory = CacheDataSource.Factory().apply {
|
if (simpleCache != null) {
|
||||||
setCache(simpleCache)
|
cacheFactory = CacheDataSource.Factory().apply {
|
||||||
setUpstreamDataSourceFactory(dataSourceFactory)
|
setCache(simpleCache!!)
|
||||||
|
setUpstreamDataSourceFactory(dataSourceFactory)
|
||||||
|
}
|
||||||
|
mediaSourceFactory = DefaultMediaSourceFactory(cacheFactory)
|
||||||
|
} else {
|
||||||
|
mediaSourceFactory = DefaultMediaSourceFactory(dataSourceFactory)
|
||||||
}
|
}
|
||||||
mediaSourceFactory = DefaultMediaSourceFactory(cacheFactory)
|
|
||||||
mediaItem = MediaItem.Builder()
|
mediaItem = MediaItem.Builder()
|
||||||
.setUri(uri)
|
.setUri(uri)
|
||||||
.setMimeType(getMime(uri))
|
.setMimeType(getMime(uri))
|
||||||
|
@ -506,11 +514,15 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
} else {
|
} else {
|
||||||
newDataSourceFactory()
|
newDataSourceFactory()
|
||||||
}
|
}
|
||||||
cacheFactory = CacheDataSource.Factory().apply {
|
if (simpleCache != null) {
|
||||||
setCache(simpleCache)
|
cacheFactory = CacheDataSource.Factory().apply {
|
||||||
setUpstreamDataSourceFactory(dataSourceFactory)
|
setCache(simpleCache!!)
|
||||||
|
setUpstreamDataSourceFactory(dataSourceFactory)
|
||||||
|
}
|
||||||
|
mediaSourceFactory = DefaultMediaSourceFactory(cacheFactory)
|
||||||
|
} else {
|
||||||
|
mediaSourceFactory = DefaultMediaSourceFactory(dataSourceFactory)
|
||||||
}
|
}
|
||||||
mediaSourceFactory = DefaultMediaSourceFactory(cacheFactory)
|
|
||||||
exoPlayer.release()
|
exoPlayer.release()
|
||||||
exoPlayer = newPlayer()
|
exoPlayer = newPlayer()
|
||||||
exoPlayer.setMediaSource(mediaSourceFactory.createMediaSource(mediaItem), resumeAt)
|
exoPlayer.setMediaSource(mediaSourceFactory.createMediaSource(mediaItem), resumeAt)
|
||||||
|
@ -598,7 +610,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
deletePendingEpisodes()
|
deletePendingEpisodes()
|
||||||
releasePlayer()
|
releasePlayer()
|
||||||
simpleCache.release()
|
simpleCache?.release()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
|
||||||
finishAndRemoveTask()
|
finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue