diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 3c4a8f066f..2bcf37cc1b 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -16,7 +16,6 @@ import android.os.Looper; import android.os.Message; import android.text.TextUtils; -import android.util.Log; import android.view.View; import android.view.Window; import android.view.accessibility.CaptioningManager; @@ -2042,7 +2041,7 @@ public void setHideShutterView(boolean hideShutterView) { exoPlayerView.setHideShutterView(hideShutterView); } - public void setBufferConfig(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs, double newMaxHeapAllocationPercent, double newMinBackBufferMemoryReservePercent, double newMinBufferMemoryReservePercent, int bufferSize) { + public void setBufferConfig(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs, double newMaxHeapAllocationPercent, double newMinBackBufferMemoryReservePercent, double newMinBufferMemoryReservePercent, int cacheSize) { minBufferMs = newMinBufferMs; maxBufferMs = newMaxBufferMs; bufferForPlaybackMs = newBufferForPlaybackMs; @@ -2050,11 +2049,15 @@ public void setBufferConfig(int newMinBufferMs, int newMaxBufferMs, int newBuffe maxHeapAllocationPercent = newMaxHeapAllocationPercent; minBackBufferMemoryReservePercent = newMinBackBufferMemoryReservePercent; minBufferMemoryReservePercent = newMinBufferMemoryReservePercent; - SimpleCache simpleCache = new SimpleCache(new File(this.getContext().getCacheDir(), "RNVCache"), new LeastRecentlyUsedCacheEvictor((long) bufferSize*1024*1024), new StandaloneDatabaseProvider(this.getContext())); - cacheDataSourceFactory = - new CacheDataSource.Factory() - .setCache(simpleCache) - .setUpstreamDataSourceFactory(buildHttpDataSourceFactory(false)); + if (cacheSize == 0) { + cacheDataSourceFactory = null; + } else { + SimpleCache simpleCache = new SimpleCache(new File(this.getContext().getCacheDir(), "RNVCache"), new LeastRecentlyUsedCacheEvictor((long) cacheSize*1024*1024), new StandaloneDatabaseProvider(this.getContext())); + cacheDataSourceFactory = + new CacheDataSource.Factory() + .setCache(simpleCache) + .setUpstreamDataSourceFactory(buildHttpDataSourceFactory(false)); + } releasePlayer(); initializePlayer(); } diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 1099b8417f..5836e9f16e 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -61,7 +61,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi private static final String PROP_VOLUME = "volume"; private static final String PROP_BACK_BUFFER_DURATION_MS = "backBufferDurationMs"; private static final String PROP_BUFFER_CONFIG = "bufferConfig"; - private static final String PROP_BUFFER_CONFIG_BUFFER_SIZE = "bufferSize"; + private static final String PROP_BUFFER_CONFIG_CACHE_SIZE = "cacheSizeMB"; private static final String PROP_BUFFER_CONFIG_MIN_BUFFER_MS = "minBufferMs"; private static final String PROP_BUFFER_CONFIG_MAX_BUFFER_MS = "maxBufferMs"; private static final String PROP_BUFFER_CONFIG_BUFFER_FOR_PLAYBACK_MS = "bufferForPlaybackMs"; @@ -401,7 +401,7 @@ public void setShutterColor(final ReactExoplayerView videoView, final Integer co @ReactProp(name = PROP_BUFFER_CONFIG) public void setBufferConfig(final ReactExoplayerView videoView, @Nullable ReadableMap bufferConfig) { - int bufferSize = 0; + int cacheSize = 0; int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS; int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS; @@ -411,7 +411,7 @@ public void setBufferConfig(final ReactExoplayerView videoView, @Nullable Readab double minBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BUFFER_MEMORY_RESERVE; if (bufferConfig != null) { - bufferSize = ReactBridgeUtils.safeGetInt(bufferConfig, PROP_BUFFER_CONFIG_BUFFER_SIZE, 0); + cacheSize = ReactBridgeUtils.safeGetInt(bufferConfig, PROP_BUFFER_CONFIG_CACHE_SIZE, 0); minBufferMs = ReactBridgeUtils.safeGetInt(bufferConfig, PROP_BUFFER_CONFIG_MIN_BUFFER_MS, minBufferMs); maxBufferMs = ReactBridgeUtils.safeGetInt(bufferConfig, PROP_BUFFER_CONFIG_MAX_BUFFER_MS, maxBufferMs); bufferForPlaybackMs = ReactBridgeUtils.safeGetInt(bufferConfig, PROP_BUFFER_CONFIG_BUFFER_FOR_PLAYBACK_MS, bufferForPlaybackMs); @@ -419,7 +419,7 @@ public void setBufferConfig(final ReactExoplayerView videoView, @Nullable Readab maxHeapAllocationPercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MAX_HEAP_ALLOCATION_PERCENT, maxHeapAllocationPercent); minBackBufferMemoryReservePercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MIN_BACK_BUFFER_MEMORY_RESERVE_PERCENT, minBackBufferMemoryReservePercent); minBufferMemoryReservePercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MIN_BUFFER_MEMORY_RESERVE_PERCENT, minBufferMemoryReservePercent); - videoView.setBufferConfig(minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs, maxHeapAllocationPercent, minBackBufferMemoryReservePercent, minBufferMemoryReservePercent, bufferSize); + videoView.setBufferConfig(minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs, maxHeapAllocationPercent, minBackBufferMemoryReservePercent, minBufferMemoryReservePercent, cacheSize); } } diff --git a/docs/pages/component/props.md b/docs/pages/component/props.md index e4ecb97473..7a05ee2edc 100644 --- a/docs/pages/component/props.md +++ b/docs/pages/component/props.md @@ -118,6 +118,7 @@ bufferForPlaybackAfterRebufferMs | number | The default duration of media that m 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, it will allow applications to store video data for a while in the cache folder, it is useful to decrease bandwidth usage when repeating small videos. Android only. This prop should only be set when you are setting the source, changing it after the media is loaded will cause it to be reloaded. diff --git a/examples/basic/src/VideoPlayer.tsx b/examples/basic/src/VideoPlayer.tsx index 7a2d821e77..3b6290745c 100644 --- a/examples/basic/src/VideoPlayer.tsx +++ b/examples/basic/src/VideoPlayer.tsx @@ -303,7 +303,7 @@ class VideoPlayer extends Component { }; onEnd = () => { - // this.channelUp(); + !this.state.loop && this.channelUp(); }; toggleFullscreen() { @@ -759,7 +759,7 @@ class VideoPlayer extends Component { onAspectRatio={this.onAspectRatio} onReadyForDisplay={this.onReadyForDisplay} onBuffer={this.onVideoBuffer} - repeat + repeat={this.state.loop} selectedTextTrack={this.state.selectedTextTrack} selectedAudioTrack={this.state.selectedAudioTrack} playInBackground={false} @@ -768,7 +768,7 @@ class VideoPlayer extends Component { maxBufferMs: 50000, bufferForPlaybackMs: 2500, bufferForPlaybackAfterRebufferMs: 5000, - bufferSize: 200, + cacheSizeMB: 200, }} /> </TouchableOpacity> diff --git a/src/VideoNativeComponent.ts b/src/VideoNativeComponent.ts index 90032917de..c6b78c6a92 100644 --- a/src/VideoNativeComponent.ts +++ b/src/VideoNativeComponent.ts @@ -103,7 +103,7 @@ type BufferConfig = Readonly<{ maxHeapAllocationPercent?: number; minBackBufferMemoryReservePercent?: number; minBufferMemoryReservePercent?: number; - bufferSize?: number; + cacheSizeMB?: number; }>; type SelectedVideoTrack = Readonly<{ diff --git a/src/types/video.ts b/src/types/video.ts index 415c69c530..8d340007a5 100644 --- a/src/types/video.ts +++ b/src/types/video.ts @@ -68,6 +68,7 @@ export type BufferConfig = { maxHeapAllocationPercent?: number; minBackBufferMemoryReservePercent?: number; minBufferMemoryReservePercent?: number; + cacheSizeMB?: number; }; export enum SelectedTrackType {