-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
compose-video/src/main/kotlin/io/sanghun/compose/video/cache/VideoPlayerCacheConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.sanghun.compose.video.cache | ||
|
||
import androidx.compose.runtime.Immutable | ||
|
||
/** | ||
* Settings for video cache. | ||
* The cache method is the Last Recently Used (LRU) method. | ||
* | ||
* [VideoPlayerCacheConfig] lets you set whether to enable the cache and the maximum cache size in bytes. | ||
* | ||
* @param enableCache Sets whether cache is enabled. Default is true. | ||
* @param maxCacheSize Sets the maximum cache capacity in bytes. If the cache builds up as much as the set capacity, it is deleted from the oldest cache. Default is 104857600 bytes (100MB). | ||
*/ | ||
@Immutable | ||
data class VideoPlayerCacheConfig( | ||
val enableCache: Boolean, | ||
val maxCacheSize: Long, | ||
) { | ||
|
||
companion object { | ||
|
||
/** | ||
* Default config for cache. | ||
*/ | ||
val Default = VideoPlayerCacheConfig( | ||
enableCache = true, | ||
maxCacheSize = 100 * 1024 * 1024, | ||
) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
compose-video/src/main/kotlin/io/sanghun/compose/video/cache/VideoPlayerCacheManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.sanghun.compose.video.cache | ||
|
||
import android.content.Context | ||
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider | ||
import com.google.android.exoplayer2.upstream.cache.Cache | ||
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor | ||
import com.google.android.exoplayer2.upstream.cache.SimpleCache | ||
import java.io.File | ||
|
||
internal object VideoPlayerCacheManager { | ||
|
||
private lateinit var cacheInstance: Cache | ||
|
||
fun initializeOrGetInstance(context: Context, maxCacheBytes: Long): Cache { | ||
if (::cacheInstance.isInitialized) { | ||
return cacheInstance | ||
} | ||
|
||
cacheInstance = SimpleCache( | ||
File(context.cacheDir, "video"), | ||
LeastRecentlyUsedCacheEvictor(maxCacheBytes), | ||
StandaloneDatabaseProvider(context) | ||
) | ||
|
||
return cacheInstance | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.