Unverified Commit 62f72214 authored by Hampton Maxwell's avatar Hampton Maxwell Committed by GitHub
Browse files

Merge pull request #1310 from nfb-onf/maximumBitRate-adaptive-streaming

Support for maximum bit rate adaptive streaming
parents b65bdb6a 00dac26a
Loading
Loading
Loading
Loading
+14 −0
Changes for README.md: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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: 
+1 −0
Changes for Video.js: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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,
+12 −0
Changes for android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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;
+6 −0
Changes for android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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 = "maxBitRate";
    private static final String PROP_PLAY_IN_BACKGROUND = "playInBackground";
    private static final String PROP_DISABLE_FOCUS = "disableFocus";
    private static final String PROP_FULLSCREEN = "fullscreen";
@@ -201,6 +202,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
        videoView.setRateModifier(rate);
    }

    @ReactProp(name = PROP_MAXIMUM_BIT_RATE)
    public void setMaxBitRate(final ReactExoplayerView videoView, final int maxBitRate) {
        videoView.setMaxBitRateModifier(maxBitRate);
    }

    @ReactProp(name = PROP_PLAY_IN_BACKGROUND, defaultBoolean = false)
    public void setPlayInBackground(final ReactExoplayerView videoView, final boolean playInBackground) {
        videoView.setPlayInBackground(playInBackground);
+11 −0
Changes for ios/Video/RCTVideo.m: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ static int const RCTVideoUnset = -1;
  /* Keep track of any modifiers, need to be applied after each play */
  float _volume;
  float _rate;
  float _maxBitRate;

  BOOL _muted;
  BOOL _paused;
  BOOL _repeat;
@@ -337,6 +339,7 @@ static int const RCTVideoUnset = -1;
      _playerItem = playerItem;
      [self addPlayerItemObservers];
      [self setFilter:_filterName];
      [self setMaxBitRate:_maxBitRate];
      
      [_player pause];
      [_playerViewController.view removeFromSuperview];
@@ -853,6 +856,12 @@ static int const RCTVideoUnset = -1;
  [self applyModifiers];
}

- (void)setMaxBitRate:(float) maxBitRate {
  _maxBitRate = maxBitRate;
  [self applyModifiers];
}


- (void)applyModifiers
{
  if (_muted) {
@@ -863,6 +872,8 @@ static int const RCTVideoUnset = -1;
    [_player setMuted:NO];
  }
  
  _playerItem.preferredPeakBitRate = _maxBitRate;
  
  [self setSelectedAudioTrack:_selectedAudioTrack];
  [self setSelectedTextTrack:_selectedTextTrack];
  [self setResizeMode:_resizeMode];
Loading