Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for maximum bit rate adaptive streaming #1310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ var styles = StyleSheet.create({
* [hideShutterView](#hideshutterview)
* [id](#id)
* [ignoreSilentSwitch](#ignoresilentswitch)
* [maxBitRate](#maxbitrate)
* [muted](#muted)
* [paused](#paused)
* [playInBackground](#playinbackground)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -246,6 +247,9 @@ private void initializePlayer() {
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);
Expand Down Expand Up @@ -909,6 +913,14 @@ public void setRateModifier(float newRate) {
}
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -201,6 +202,11 @@ public void setRate(final ReactExoplayerView videoView, final float rate) {
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);
Expand Down
13 changes: 12 additions & 1 deletion ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ @implementation RCTVideo
/* Keep track of any modifiers, need to be applied after each play */
float _volume;
float _rate;
float _maxBitRate;

BOOL _muted;
BOOL _paused;
BOOL _repeat;
Expand Down Expand Up @@ -337,7 +339,8 @@ - (void)setSrc:(NSDictionary *)source
_playerItem = playerItem;
[self addPlayerItemObservers];
[self setFilter:_filterName];

[self setMaxBitRate:_maxBitRate];

[_player pause];
[_playerViewController.view removeFromSuperview];
_playerViewController = nil;
Expand Down Expand Up @@ -853,6 +856,12 @@ - (void)setVolume:(float)volume
[self applyModifiers];
}

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


- (void)applyModifiers
{
if (_muted) {
Expand All @@ -863,6 +872,8 @@ - (void)applyModifiers
[_player setMuted:NO];
}

_playerItem.preferredPeakBitRate = _maxBitRate;

[self setSelectedAudioTrack:_selectedAudioTrack];
[self setSelectedTextTrack:_selectedTextTrack];
[self setResizeMode:_resizeMode];
Expand Down
1 change: 1 addition & 0 deletions ios/Video/RCTVideoManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ - (dispatch_queue_t)methodQueue
}

RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(maxBitRate, float);
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
RCT_EXPORT_VIEW_PROPERTY(allowsExternalPlayback, BOOL);
Expand Down