diff --git a/README.md b/README.md index 96c17151..14de6397 100644 --- a/README.md +++ b/README.md @@ -583,6 +583,9 @@ Sets the media source. You can pass an asset loaded via require or an object wit The docs for this prop are incomplete and will be updated as each option is investigated and tested. +#### maximumBitRate +Sets the maximum bit rate for HLS media sources. If an HLS m3u8 manifest describes multiple streams, the maximum bit rate determines the video stream selected + ##### Asset loaded via require Example: diff --git a/Video.js b/Video.js index 77b02f0a..60bf2b02 100644 --- a/Video.js +++ b/Video.js @@ -330,6 +330,7 @@ Video.propTypes = { // Opaque type returned by require('./video.mp4') PropTypes.number ]), + maximumBitRate: PropTypes.number, resizeMode: PropTypes.string, poster: PropTypes.string, posterResizeMode: Image.propTypes.resizeMode, 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 7d69368e..2cd4b046 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -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; 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 4d1ec286..7c7f6baa 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -47,6 +47,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager