diff --git a/README.md b/README.md index 1527448758..86fe2bc5d1 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,7 @@ var styles = StyleSheet.create({ * [id](#id) * [ignoreSilentSwitch](#ignoresilentswitch) * [maxBitRate](#maxbitrate) +* [maxResolution](#maxresolution) * [minLoadRetryCount](#minLoadRetryCount) * [muted](#muted) * [paused](#paused) @@ -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. diff --git a/Video.js b/Video.js index 81c1b80202..f02d34eea9 100644 --- a/Video.js +++ b/Video.js @@ -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, diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index dcadee85f4..5439be3930 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -53,6 +53,7 @@ @implementation RCTVideo float _volume; float _rate; float _maxBitRate; + NSDictionary * _maxResolution; BOOL _muted; BOOL _paused; @@ -352,6 +353,7 @@ - (void)setSrc:(NSDictionary *)source [self addPlayerItemObservers]; [self setFilter:_filterName]; [self setMaxBitRate:_maxBitRate]; + [self setMaxResolution:_maxResolution]; [_player pause]; [_playerViewController.view removeFromSuperview]; @@ -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 { @@ -969,6 +987,7 @@ - (void)applyModifiers } [self setMaxBitRate:_maxBitRate]; + [self setMaxResolution:_maxResolution]; [self setSelectedAudioTrack:_selectedAudioTrack]; [self setSelectedTextTrack:_selectedTextTrack]; [self setResizeMode:_resizeMode]; diff --git a/ios/Video/RCTVideoManager.m b/ios/Video/RCTVideoManager.m index a608f32e6b..d41e256688 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -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);