Commit 11db3439 authored by Ash Mishra's avatar Ash Mishra
Browse files

Support for HLS maximum bit rate adaptive streaming

parent d8a19e66
Loading
Loading
Loading
Loading
+3 −0
Changes for README.md: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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: 
+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
  ]),
  maximumBitRate: PropTypes.number,
  resizeMode: PropTypes.string,
  poster: PropTypes.string,
  posterResizeMode: Image.propTypes.resizeMode,
+14 −0
Changes for android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java: 14 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 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;
+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 = "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);
+9 −0
Changes for ios/Video/RCTVideo.m: 9 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 _maximumBitRate;

  BOOL _muted;
  BOOL _paused;
  BOOL _repeat;
@@ -338,6 +340,8 @@ static int const RCTVideoUnset = -1;
      [self addPlayerItemObservers];
      [self setFilter:_filterName];

      _playerItem.preferredPeakBitRate = _maximumBitRate;
      
      [_player pause];
      [_playerViewController.view removeFromSuperview];
      _playerViewController = nil;
@@ -378,6 +382,11 @@ static int const RCTVideoUnset = -1;
  _videoLoadStarted = YES;
}

- (void)setMaximumBitRate:(float) maximumBitRate {
  _maximumBitRate = maximumBitRate;
  [self applyModifiers];
}

- (NSURL*) urlFilePath:(NSString*) filepath {
  if ([filepath containsString:@"file://"]) {
    return [NSURL URLWithString:filepath];
Loading