From cf651f0bd1bea3312888fd78ed348ffe49667273 Mon Sep 17 00:00:00 2001 From: Amit Tandel Date: Thu, 24 Jan 2019 14:37:08 +0530 Subject: [PATCH 1/4] MaxResolution support added for iOS --- README.md | 13 +++++++++++++ Video.js | 4 ++++ ios/Video/RCTVideo.m | 17 +++++++++++++++++ ios/Video/RCTVideoManager.m | 1 + 4 files changed, 35 insertions(+) diff --git a/README.md b/README.md index 05337141f5..4f498e108a 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,7 @@ var styles = StyleSheet.create({ * [id](#id) * [ignoreSilentSwitch](#ignoresilentswitch) * [maxBitRate](#maxbitrate) +* [maxResolution](#maxresolution) * [muted](#muted) * [paused](#paused) * [playInBackground](#playinbackground) @@ -475,6 +476,18 @@ 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. + +Default: 0. Don't limit the maxResolution. + +Example: +``` +maxResolution={width:360, height: 180} +``` + +Platforms: iOS + #### muted Controls whether the audio is muted * **false (default)** - Don't mute audio diff --git a/Video.js b/Video.js index 92544467c0..f301e64007 100644 --- a/Video.js +++ b/Video.js @@ -340,6 +340,10 @@ Video.propTypes = { 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 52b0342a6b..5d5fcd5cb1 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; @@ -343,6 +344,7 @@ - (void)setSrc:(NSDictionary *)source [self addPlayerItemObservers]; [self setFilter:_filterName]; [self setMaxBitRate:_maxBitRate]; + [self setMaxResolution:_maxResolution]; [_player pause]; [_playerViewController.view removeFromSuperview]; @@ -884,6 +886,20 @@ - (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[@"width"] isKindOfClass:[NSNumber class]]) { + width = [maxResolution[@"width"] intValue]; + } + + _playerItem.preferredMaximumResolution = CGSizeMake(width, height); +} + - (void)applyModifiers { @@ -896,6 +912,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 1ca1b5b402..3c02b38a92 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); From cfc0259814dd857cc84d90d547534e4f8c70e478 Mon Sep 17 00:00:00 2001 From: Amit Tandel Date: Thu, 24 Jan 2019 16:22:14 +0530 Subject: [PATCH 2/4] Height fix --- ios/Video/RCTVideo.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 5d5fcd5cb1..eff3544527 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -893,8 +893,8 @@ - (void)setMaxResolution:(NSDictionary *) maxResolution { width = [maxResolution[@"width"] intValue]; } int height = 0; - if ([maxResolution[@"width"] isKindOfClass:[NSNumber class]]) { - width = [maxResolution[@"width"] intValue]; + if ([maxResolution[@"height"] isKindOfClass:[NSNumber class]]) { + height = [maxResolution[@"height"] intValue]; } _playerItem.preferredMaximumResolution = CGSizeMake(width, height); From 389ba02fdbe1d20b5cfd58265eef5c30b66b697c Mon Sep 17 00:00:00 2001 From: Amit Tandel Date: Thu, 24 Jan 2019 17:04:58 +0530 Subject: [PATCH 3/4] iOS 11 check --- ios/Video/RCTVideo.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index eff3544527..4603447967 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -897,7 +897,9 @@ - (void)setMaxResolution:(NSDictionary *) maxResolution { height = [maxResolution[@"height"] intValue]; } - _playerItem.preferredMaximumResolution = CGSizeMake(width, height); + if (@available(iOS 11.0, *)) { + _playerItem.preferredMaximumResolution = CGSizeMake(width, height); + } } From cf21ddc916fa8ea07447ba03407c3373f1927d32 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Tue, 12 Mar 2019 23:40:43 -0700 Subject: [PATCH 4/4] More detail on maxResolution --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 591a710a46..86fe2bc5d1 100644 --- a/README.md +++ b/README.md @@ -482,13 +482,19 @@ 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. +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. -Default: 0. Don't limit the maxResolution. +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} +maxResolution={ width: 360, height: 180 } ``` Platforms: iOS