Skip to content

Commit f4fe538

Browse files
committed
docs: add video caching section to README
1 parent 9393f41 commit f4fe538

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

README.MD

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- [Fullscreen Mode](#️-fullscreen-mode)
4949
- [Picture-in-Picture (PiP)](#-picture-in-picture-pip)
5050
- [Audio Mode](#-audio-mode)
51+
- [Video Caching](#-video-caching)
5152
- [Metadata Support](#-metadata-support)
5253
- [Example Usage](#example-usage)
5354
- [Basic Example](#-basic-example)
@@ -71,6 +72,7 @@ Try the online demo here : [🎥 Live Demo](https://kdroidfilter.github.io/Compo
7172
- **Fullscreen Mode**: Toggle between windowed and fullscreen playback modes.
7273
- **Picture-in-Picture (PiP)**: Continue watching in a floating window on Android (8.0+) and iOS.
7374
- **Audio Mode**: Configure audio interruption behavior and iOS silent switch handling.
75+
- **Video Caching**: Opt-in disk caching for video data on Android and iOS, ideal for scroll-based UIs.
7476
- **Error handling** Simple error handling for network or playback issues.
7577

7678
## ✨ Supported Video Formats
@@ -549,6 +551,40 @@ val playerState = rememberVideoPlayerState(
549551
> [!NOTE]
550552
> Audio mode is only effective on **Android** and **iOS**. On desktop and web, the parameter is accepted but ignored.
551553
554+
### 💾 Video Caching
555+
556+
You can enable disk-based caching so that video data fetched via `openUri()` is stored locally. Subsequent plays of the same URL load from the cache instead of re-downloading, which is especially useful for scroll-based UIs like TikTok/Reels-style `VerticalPager`.
557+
558+
```kotlin
559+
val playerState = rememberVideoPlayerState(
560+
cacheConfig = CacheConfig(
561+
enabled = true,
562+
maxCacheSizeBytes = 200L * 1024L * 1024L // 200 MB
563+
)
564+
)
565+
```
566+
567+
| Parameter | Description | Default |
568+
| :--- | :--- | :---: |
569+
| `enabled` | Whether caching is active | `false` |
570+
| `maxCacheSizeBytes` | Maximum disk space for the cache (LRU eviction) | `100 MB` |
571+
572+
To clear the cache programmatically:
573+
574+
```kotlin
575+
playerState.clearCache()
576+
```
577+
578+
| Platform | Status | Implementation |
579+
| :--- | :---: | :--- |
580+
| **Android** || Media3 `SimpleCache` with `LeastRecentlyUsedCacheEvictor` |
581+
| **iOS** || `NSURLCache` with increased disk capacity |
582+
| **Desktop** || No-op (config accepted but ignored) |
583+
| **Web** || No-op (browser manages its own HTTP cache) |
584+
585+
> [!NOTE]
586+
> Caching only applies to URIs opened via `openUri()`. Local files and assets are not cached. The cache is shared across all player instances, so multiple players benefit from the same cached data.
587+
552588
## 🔍 Metadata Support
553589

554590
> [!WARNING]

0 commit comments

Comments
 (0)