diff --git a/Video.js b/Video.js index b492d48b..f1119150 100644 --- a/Video.js +++ b/Video.js @@ -470,6 +470,7 @@ Video.propTypes = { ignoreSilentSwitch: PropTypes.oneOf(['ignore', 'obey']), reportBandwidth: PropTypes.bool, disableFocus: PropTypes.bool, + disableBuffering: PropTypes.bool, controls: PropTypes.bool, audioOnly: PropTypes.bool, currentTime: PropTypes.number, diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index d7c33214..7881c914 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -26,6 +26,7 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.util.RNLog; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.DefaultRenderersFactory; @@ -70,6 +71,7 @@ import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultAllocator; import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; import com.google.android.exoplayer2.upstream.HttpDataSource; +import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Util; import java.net.CookieHandler; @@ -148,6 +150,7 @@ class ReactExoplayerView extends FrameLayout implements private Dynamic textTrackValue; private ReadableArray textTracks; private boolean disableFocus; + private boolean disableBuffering; private boolean preventsDisplaySleepDuringVideoPlayback = true; private float mProgressUpdateInterval = 250.0f; private boolean playInBackground = false; @@ -183,7 +186,7 @@ class ReactExoplayerView extends FrameLayout implements } } }; - + public double getPositionInFirstPeriodMsForCurrentWindow(long currentPosition) { Timeline.Window window = new Timeline.Window(); if(!player.getCurrentTimeline().isEmpty()) { @@ -388,6 +391,28 @@ class ReactExoplayerView extends FrameLayout implements view.layout(view.getLeft(), view.getTop(), view.getMeasuredWidth(), view.getMeasuredHeight()); } + private class RNVLoadControl extends DefaultLoadControl { + public RNVLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBufferMs, int bufferForPlaybackMs, int bufferForPlaybackAfterRebufferMs, int targetBufferBytes, boolean prioritizeTimeOverSizeThresholds, int backBufferDurationMs, boolean retainBackBufferFromKeyframe) { + super(allocator, + minBufferMs, + maxBufferMs, + bufferForPlaybackMs, + bufferForPlaybackAfterRebufferMs, + targetBufferBytes, + prioritizeTimeOverSizeThresholds, + backBufferDurationMs, + retainBackBufferFromKeyframe); + } + + @Override + public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) { + if (ReactExoplayerView.this.disableBuffering) { + return false; + } + return super.shouldContinueLoading(playbackPositionUs, bufferedDurationUs, playbackSpeed); + } + } + private void initializePlayer() { ReactExoplayerView self = this; // This ensures all props have been settled, to avoid async racing conditions. @@ -401,19 +426,24 @@ class ReactExoplayerView extends FrameLayout implements .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); - DefaultLoadControl.Builder defaultLoadControlBuilder = new DefaultLoadControl.Builder(); - defaultLoadControlBuilder.setAllocator(allocator); - defaultLoadControlBuilder.setBufferDurationsMs(minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs); - defaultLoadControlBuilder.setTargetBufferBytes(-1); - defaultLoadControlBuilder.setPrioritizeTimeOverSizeThresholds(true); - DefaultLoadControl defaultLoadControl = defaultLoadControlBuilder.createDefaultLoadControl(); + RNVLoadControl loadControl = new RNVLoadControl( + allocator, + minBufferMs, + maxBufferMs, + bufferForPlaybackMs, + bufferForPlaybackAfterRebufferMs, + -1, + true, + DefaultLoadControl.DEFAULT_BACK_BUFFER_DURATION_MS, + DefaultLoadControl.DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME + ); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()) .setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) .setTrackSelector​(trackSelector) .setBandwidthMeter(bandwidthMeter) - .setLoadControl(defaultLoadControl) + .setLoadControl(loadControl) .build(); player.addListener(self); player.addMetadataOutput(self); @@ -1282,6 +1312,10 @@ class ReactExoplayerView extends FrameLayout implements this.disableFocus = disableFocus; } + public void setDisableBuffering(boolean disableBuffering) { + this.disableBuffering = disableBuffering; + } + public void setFullscreen(boolean fullscreen) { if (fullscreen == isFullscreen) { return; // Avoid generating events when nothing is changing diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 0d81e0b2..2fc12e42 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -63,6 +63,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager