diff --git a/README.md b/README.md index 0868e6e7..07fbfd88 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,7 @@ var styles = StyleSheet.create({ * [hideShutterView](#hideshutterview) * [id](#id) * [ignoreSilentSwitch](#ignoresilentswitch) +* [maxBitRate](#maxbitrate) * [muted](#muted) * [paused](#paused) * [playInBackground](#playinbackground) @@ -444,6 +445,18 @@ Controls the iOS silent switch behavior Platforms: iOS +#### maxBitRate +Sets the desired limit, in bits per second, of network bandwidth consumption when multiple video streams are available for a playlist. + +Default: 0. Don't limit the maxBitRate. + +Example: +``` +maxBitRate={2000000} // 2 megabits +``` + +Platforms: Android ExoPlayer, iOS + #### muted Controls whether the audio is muted * **false (default)** - Don't mute audio @@ -593,6 +606,7 @@ 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. + ##### Asset loaded via require Example: diff --git a/Video.js b/Video.js index 60dd3f54..a43b2e0e 100644 --- a/Video.js +++ b/Video.js @@ -330,6 +330,7 @@ Video.propTypes = { // Opaque type returned by require('./video.mp4') PropTypes.number ]), + maxBitRate: 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 033329b7..a18f7cff 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 maxBitRate = 0; private long seekTime = C.TIME_UNSET; private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; @@ -246,6 +247,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(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); + 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); @@ -909,6 +913,14 @@ class ReactExoplayerView extends FrameLayout implements } } + public void setMaxBitRateModifier(int newMaxBitRate) { + maxBitRate = newMaxBitRate; + if (player != null) { + trackSelector.setParameters(trackSelector.buildUponParameters() + .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); + } + } + 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 fb72f434..84cc620a 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