feat(android): cache (#3514)
* feat: android cache * docs: bufferSize * Revert "docs: bufferSize" This reverts commit 09637b134e121b9ca3ffd78f2f5bc657319ed67a. * fix: cacheSize name * feat: singleton android cache * fix: local cache resolve * fix: lint * docs: android cache * chore: merge conflict * fix: lint * chore: useCache button * chore: fix state in the sample * fix: cache factory * chore: update cacheSizeMB docs --------- Co-authored-by: Olivier Bouillet <freeboub@gmail.com>
This commit is contained in:
@@ -63,7 +63,7 @@ Adjust the buffer settings. This prop takes an object with one or more of the pr
|
||||
| maxHeapAllocationPercent | number | The percentage of available heap that the video can use to buffer, between 0 and 1 |
|
||||
| minBackBufferMemoryReservePercent | number | The percentage of available app memory at which during startup the back buffer will be disabled, between 0 and 1 |
|
||||
| minBufferMemoryReservePercent | number | The percentage of available app memory to keep in reserve that prevents buffer from using it, between 0 and 1 |
|
||||
|
||||
| cacheSizeMB | number | Cache size in MB, enabling this to prevent new src requests and save bandwidth while repeating videos, or 0 to disable. Android only. |
|
||||
|
||||
Example with default values:
|
||||
|
||||
@@ -74,9 +74,12 @@ bufferConfig={{
|
||||
bufferForPlaybackMs: 2500,
|
||||
bufferForPlaybackAfterRebufferMs: 5000,
|
||||
backBufferDurationMs: 120000,
|
||||
cacheSizeMB: 0
|
||||
}}
|
||||
```
|
||||
|
||||
Please note that the Android cache is a global cache that is shared among all components; individual components can still opt out of caching behavior by setting cacheSizeMB to 0, but multiple components with a positive cacheSizeMB will be sharing the same one, and the cache size will always be the first value set; it will not change during the app's lifecycle.
|
||||
|
||||
### `chapters`
|
||||
|
||||
<PlatformsList types={['tvOS']} />
|
||||
@@ -610,7 +613,7 @@ Pass directly the asset to play (deprecated)
|
||||
|
||||
```javascript
|
||||
const sintel = require('./sintel.mp4');
|
||||
source={ sintel };
|
||||
source = {sintel};
|
||||
```
|
||||
|
||||
Or by using an uri (starting from 6.0.0-beta.6)
|
||||
@@ -620,7 +623,6 @@ const sintel = require('./sintel.mp4');
|
||||
source={{ uri: sintel }}
|
||||
```
|
||||
|
||||
|
||||
#### URI string
|
||||
|
||||
A number of URI schemes are supported by passing an object with a `uri` attribute.
|
||||
@@ -725,14 +727,14 @@ source={{
|
||||
|
||||
### `subtitleStyle`
|
||||
|
||||
| Property | Description | Platforms |
|
||||
| ------------- | ----------------------------------------------------------------------- | --------- |
|
||||
| fontSize | Adjust the font size of the subtitles. Default: font size of the device | Android |
|
||||
| paddingTop | Adjust the top padding of the subtitles. Default: 0 | Android |
|
||||
| paddingBottom | Adjust the bottom padding of the subtitles. Default: 0 | Android |
|
||||
| paddingLeft | Adjust the left padding of the subtitles. Default: 0 | Android |
|
||||
| paddingRight | Adjust the right padding of the subtitles. Default: 0 | Android |
|
||||
| opacity | Adjust the visibility of subtitles with 0 hiding and 1 fully showing them. Android supports float values between 0 and 1 for varying opacity levels, whereas iOS supports only 0 or 1. Default: 1. | Android, iOS |
|
||||
| Property | Description | Platforms |
|
||||
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
|
||||
| fontSize | Adjust the font size of the subtitles. Default: font size of the device | Android |
|
||||
| paddingTop | Adjust the top padding of the subtitles. Default: 0 | Android |
|
||||
| paddingBottom | Adjust the bottom padding of the subtitles. Default: 0 | Android |
|
||||
| paddingLeft | Adjust the left padding of the subtitles. Default: 0 | Android |
|
||||
| paddingRight | Adjust the right padding of the subtitles. Default: 0 | Android |
|
||||
| opacity | Adjust the visibility of subtitles with 0 hiding and 1 fully showing them. Android supports float values between 0 and 1 for varying opacity levels, whereas iOS supports only 0 or 1. Default: 1. | Android, iOS |
|
||||
|
||||
Example:
|
||||
|
||||
|
@@ -1,22 +1,30 @@
|
||||
# Caching
|
||||
|
||||
Caching is currently only supported on `iOS` platforms with a CocoaPods setup.
|
||||
Caching is supported on `iOS` platforms with a CocoaPods setup, and on `android` using `SimpleCache`.
|
||||
|
||||
## Technology
|
||||
## Android
|
||||
|
||||
Android uses a LRU `SimpleCache` with a variable cache size that can be specified by bufferConfig - cacheSizeMB. This creates a folder named `RNVCache` in the app's `cache` folder. Do note RNV does not yet offer a native call to flush the cache, it can be flushed by clearing the app's cache.
|
||||
|
||||
In addition, this resolves RNV6's repeated source URI call problem when looping a video on Android.
|
||||
|
||||
## iOS
|
||||
|
||||
### Technology
|
||||
|
||||
The cache is backed by [SPTPersistentCache](https://github.com/spotify/SPTPersistentCache) and [DVAssetLoaderDelegate](https://github.com/vdugnist/DVAssetLoaderDelegate).
|
||||
|
||||
## How Does It Work
|
||||
### How Does It Work
|
||||
|
||||
The caching is based on the url of the asset.
|
||||
SPTPersistentCache is a LRU ([Least Recently Used](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU))) cache.
|
||||
SPTPersistentCache is a LRU ([Least Recently Used](<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)>)) cache.
|
||||
|
||||
## Restrictions
|
||||
### Restrictions
|
||||
|
||||
Currently, caching is only supported for URLs that end in a `.mp4`, `.m4v`, or `.mov` extension. In future versions, URLs that end in a query string (e.g. test.mp4?resolution=480p) will be support once dependencies allow access to the `Content-Type` header. At this time, HLS playlists (.m3u8) and videos that sideload text tracks are not supported and will bypass the cache.
|
||||
Currently, caching is only supported for URLs that end in a `.mp4`, `.m4v`, or `.mov` extension. In future versions, URLs that end in a query string (e.g. test.mp4?resolution=480p) will be support once dependencies allow access to the `Content-Type` header. At this time, HLS playlists (.m3u8) and videos that sideload text tracks are not supported and will bypass the cache.
|
||||
|
||||
You will also receive warnings in the Xcode logs by using the `debug` mode. So if you are not 100% sure if your video is cached, check your Xcode logs!
|
||||
|
||||
By default files expire after 30 days and the maximum cache size is 100mb.
|
||||
|
||||
In a future release the cache might have more configurable options.
|
||||
In a future release the cache might have more configurable options.
|
||||
|
Reference in New Issue
Block a user