Support for HLS maximum bit rate adaptive streaming

This commit is contained in:
Ash Mishra
2018-10-29 09:53:52 -07:00
parent d8a19e66c3
commit 11db343987
6 changed files with 34 additions and 0 deletions

View File

@@ -110,6 +110,7 @@ class ReactExoplayerView extends FrameLayout implements
private boolean isBuffering;
private float rate = 1f;
private float audioVolume = 1f;
private int maximumBitRate = 0;
private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
@@ -244,6 +245,9 @@ class ReactExoplayerView extends FrameLayout implements
if (player == null) {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
trackSelector.setParameters(trackSelector.buildUponParameters()
.setMaxVideoBitrate(maximumBitRate));
DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
DefaultLoadControl defaultLoadControl = new DefaultLoadControl(allocator, minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs, -1, true);
player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, defaultLoadControl);
@@ -906,6 +910,16 @@ class ReactExoplayerView extends FrameLayout implements
}
}
public void setMaximumBitRateModifier(int newMaximumBitRate) {
if (newMaximumBitRate==0) newMaximumBitRate = Integer.MAX_VALUE;
maximumBitRate = newMaximumBitRate;
if (player != null) {
trackSelector.setParameters(trackSelector.buildUponParameters()
.setMaxVideoBitrate(maximumBitRate));
}
}
public void setPlayInBackground(boolean playInBackground) {
this.playInBackground = playInBackground;

View File

@@ -47,6 +47,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
private static final String PROP_SEEK = "seek";
private static final String PROP_RATE = "rate";
private static final String PROP_MAXIMUM_BIT_RATE = "maximumBitRate";
private static final String PROP_PLAY_IN_BACKGROUND = "playInBackground";
private static final String PROP_DISABLE_FOCUS = "disableFocus";
private static final String PROP_FULLSCREEN = "fullscreen";
@@ -200,6 +201,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
videoView.setRateModifier(rate);
}
@ReactProp(name = PROP_MAXIMUM_BIT_RATE)
public void setMaximumBitRate(final ReactExoplayerView videoView, final int maximumBitRate) {
videoView.setMaximumBitRateModifier(maximumBitRate);
}
@ReactProp(name = PROP_PLAY_IN_BACKGROUND, defaultBoolean = false)
public void setPlayInBackground(final ReactExoplayerView videoView, final boolean playInBackground) {
videoView.setPlayInBackground(playInBackground);