Skip to content

feat: add opt-in video caching for Android and iOS#197

Merged
kdroidFilter merged 3 commits intomasterfrom
feat/video-cache-config
Apr 11, 2026
Merged

feat: add opt-in video caching for Android and iOS#197
kdroidFilter merged 3 commits intomasterfrom
feat/video-cache-config

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

Summary

  • Add CacheConfig data class (opt-in, disabled by default) with configurable max cache size
  • Android: shared SimpleCache singleton with LeastRecentlyUsedCacheEvictor, injected via CacheDataSource.Factory into ExoPlayer's DefaultMediaSourceFactory
  • iOS: configure NSURLCache with increased disk capacity so AVPlayer's HTTP responses are cached transparently
  • JVM/Web: accept CacheConfig parameter (no-op)
  • Add clearCache() to VideoPlayerState interface (default no-op, implemented on Android & iOS)
  • Add media3-datasource and media3-database explicit dependencies

Usage

val playerState = rememberVideoPlayerState(
    cacheConfig = CacheConfig(enabled = true, maxCacheSizeBytes = 200L * 1024 * 1024)
)
playerState.openUri("https://example.com/video.mp4") // cached on disk

Closes #34

Test plan

  • Android: verify video plays normally with CacheConfig(enabled = false) (default)
  • Android: enable cache, play a video, kill the player, replay the same URL — should load from cache (check logcat for cache hits)
  • Android: verify clearCache() removes cached data
  • iOS: same flow — enable cache, play, replay, verify faster load
  • iOS: verify clearCache() clears NSURLCache
  • JVM/Web: verify no compilation errors, config is ignored gracefully
  • Verify existing tests still pass on all targets

Add CacheConfig API that enables disk-based caching of video data
fetched via openUri(). On Android this uses Media3 SimpleCache with
LRU eviction; on iOS it configures NSURLCache with increased disk
capacity. Other platforms accept the config but treat it as a no-op.

Closes #34
@kdroidFilter kdroidFilter merged commit 5ee4dc0 into master Apr 11, 2026
10 checks passed
@kdroidFilter kdroidFilter deleted the feat/video-cache-config branch April 11, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add video caching

1 participant