Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Feature/preferred maximum resolution #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ var styles = StyleSheet.create({
* [id](#id)
* [ignoreSilentSwitch](#ignoresilentswitch)
* [maxBitRate](#maxbitrate)
* [maxResolution](#maxresolution)
* [minLoadRetryCount](#minLoadRetryCount)
* [muted](#muted)
* [paused](#paused)
Expand Down Expand Up @@ -480,6 +481,24 @@ maxBitRate={2000000} // 2 megabits

Platforms: Android ExoPlayer, iOS

#### maxResolution
Sets the desired limit to resolution, to limit network bandwidth consumption when multiple video streams are available for a playlist. Only supported on iOS 11 and higher.

If not set, will not limit the maxResolution.

Property | Type | Description
--- | --- | ---
width | number | If 0, allow any width. Otherwise only allow resolutions <= width
height | number | If 0, allow any height. Otherwise only allow resolutions <= height
Both width & height must be set to a non-zero value for the resolution limit to be applied.

Example:
```
maxResolution={ width: 360, height: 180 }
```

Platforms: iOS

#### minLoadRetryCount
Sets the minimum number of times to retry loading data before failing and reporting an error to the application. Useful to recover from transient internet failures.

Expand Down
4 changes: 4 additions & 0 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ Video.propTypes = {
]),
minLoadRetryCount: PropTypes.number,
maxBitRate: PropTypes.number,
maxResolution: PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number,
}),
resizeMode: PropTypes.string,
poster: PropTypes.string,
posterResizeMode: Image.propTypes.resizeMode,
Expand Down
19 changes: 19 additions & 0 deletions ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ @implementation RCTVideo
float _volume;
float _rate;
float _maxBitRate;
NSDictionary * _maxResolution;

BOOL _muted;
BOOL _paused;
Expand Down Expand Up @@ -352,6 +353,7 @@ - (void)setSrc:(NSDictionary *)source
[self addPlayerItemObservers];
[self setFilter:_filterName];
[self setMaxBitRate:_maxBitRate];
[self setMaxResolution:_maxResolution];

[_player pause];
[_playerViewController.view removeFromSuperview];
Expand Down Expand Up @@ -957,6 +959,22 @@ - (void)setMaxBitRate:(float) maxBitRate {
_playerItem.preferredPeakBitRate = maxBitRate;
}

- (void)setMaxResolution:(NSDictionary *) maxResolution {
_maxResolution = maxResolution;
int width = 0;
if ([maxResolution[@"width"] isKindOfClass:[NSNumber class]]) {
width = [maxResolution[@"width"] intValue];
}
int height = 0;
if ([maxResolution[@"height"] isKindOfClass:[NSNumber class]]) {
height = [maxResolution[@"height"] intValue];
}

if (@available(iOS 11.0, *)) {
_playerItem.preferredMaximumResolution = CGSizeMake(width, height);
}
}


- (void)applyModifiers
{
Expand All @@ -969,6 +987,7 @@ - (void)applyModifiers
}

[self setMaxBitRate:_maxBitRate];
[self setMaxResolution:_maxResolution];
[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 @@ -20,6 +20,7 @@ - (dispatch_queue_t)methodQueue

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