From e3782c4ec612701e69136cb613f4cb203836ae55 Mon Sep 17 00:00:00 2001 From: Jovan Stanimirovic Date: Thu, 22 Aug 2019 10:10:39 +0200 Subject: [PATCH 1/6] added support for automaticallyWaitsToMinimizeStalling property on iOS --- README.md | 3 +++ Video.js | 1 + ios/Video/RCTVideo.m | 16 +++++++++++++++- ios/Video/RCTVideoManager.m | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c40b188e5..9bb76c8a9b 100644 --- a/README.md +++ b/README.md @@ -351,6 +351,9 @@ Indicates whether the player should only play the audio track and instead of dis For this to work, the poster prop must be set. +#### automaticallyWaitsToMinimizeStalling +A Boolean value that indicates whether the player should automatically delay playback in order to minimize stalling. For clients linked against iOS 10.0 and later + Platforms: all #### bufferConfig diff --git a/Video.js b/Video.js index 474d7b269d..e5d56729e9 100644 --- a/Video.js +++ b/Video.js @@ -382,6 +382,7 @@ Video.propTypes = { poster: PropTypes.string, posterResizeMode: Image.propTypes.resizeMode, repeat: PropTypes.bool, + automaticallyWaitsToMinimizeStalling: PropTypes.bool, allowsExternalPlayback: PropTypes.bool, selectedAudioTrack: PropTypes.shape({ type: PropTypes.string.isRequired, diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 4710afaa5a..b4a3f063ac 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -54,6 +54,7 @@ @implementation RCTVideo float _rate; float _maxBitRate; + BOOL _automaticallyWaitsToMinimizeStalling; BOOL _muted; BOOL _paused; BOOL _repeat; @@ -376,6 +377,7 @@ - (void)setSrc:(NSDictionary *)source _isExternalPlaybackActiveObserverRegistered = YES; [self addPlayerTimeObserver]; + [self setAutomaticallyWaitsToMinimizeStalling:_automaticallyWaitsToMinimizeStalling]; //Perform on next run loop, otherwise onVideoLoadStart is nil if (self.onVideoLoadStart) { @@ -866,7 +868,13 @@ - (void)setPaused:(BOOL)paused } else if([_ignoreSilentSwitch isEqualToString:@"obey"]) { [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; } - [_player play]; + + if (@available(iOS 10.0, *) && _automaticallyWaitsToMinimizeStalling) { + [_player playImmediatelyAtRate:1.0]; + } else { + [_player play]; + [_player setRate:_rate]; + } [_player setRate:_rate]; } @@ -953,6 +961,12 @@ - (void)setMaxBitRate:(float) maxBitRate { _playerItem.preferredPeakBitRate = maxBitRate; } +- (void)setAutomaticallyWaitsToMinimizeStalling:(BOOL)waits +{ + _automaticallyWaitsToMinimizeStalling = waits; + _player.automaticallyWaitsToMinimizeStalling = waits; +} + - (void)applyModifiers { diff --git a/ios/Video/RCTVideoManager.m b/ios/Video/RCTVideoManager.m index 1614eab168..7233646f37 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -22,6 +22,7 @@ - (dispatch_queue_t)methodQueue RCT_EXPORT_VIEW_PROPERTY(maxBitRate, float); RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString); RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL); +RCT_EXPORT_VIEW_PROPERTY(automaticallyWaitsToMinimizeStalling, BOOL); RCT_EXPORT_VIEW_PROPERTY(allowsExternalPlayback, BOOL); RCT_EXPORT_VIEW_PROPERTY(textTracks, NSArray); RCT_EXPORT_VIEW_PROPERTY(selectedTextTrack, NSDictionary); From 0a361d1d0f75507e7974e5fe722f3e0c52842854 Mon Sep 17 00:00:00 2001 From: Jovan Stanimirovic Date: Thu, 22 Aug 2019 10:13:06 +0200 Subject: [PATCH 2/6] update readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bb76c8a9b..c0c28846e1 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,7 @@ var styles = StyleSheet.create({ ### Configurable props * [allowsExternalPlayback](#allowsexternalplayback) * [audioOnly](#audioonly) +* [automaticallyWaitsToMinimizeStalling](#automaticallyWaitsToMinimizeStalling) * [bufferConfig](#bufferconfig) * [controls](#controls) * [filter](#filter) @@ -351,10 +352,12 @@ Indicates whether the player should only play the audio track and instead of dis For this to work, the poster prop must be set. +Platforms: all + #### automaticallyWaitsToMinimizeStalling A Boolean value that indicates whether the player should automatically delay playback in order to minimize stalling. For clients linked against iOS 10.0 and later -Platforms: all +Platforms: iOS #### bufferConfig Adjust the buffer settings. This prop takes an object with one or more of the properties listed below. From 7615e5dcd1d0833e00723eda9f0dfb7f6b49b903 Mon Sep 17 00:00:00 2001 From: Jovan Stanimirovic Date: Thu, 22 Aug 2019 10:36:33 +0200 Subject: [PATCH 3/6] fix invert boolean property --- ios/Video/RCTVideo.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index b4a3f063ac..2791654ca3 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -89,6 +89,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher if ((self = [super init])) { _eventDispatcher = eventDispatcher; + _automaticallyWaitsToMinimizeStalling = YES; _playbackRateObserverRegistered = NO; _isExternalPlaybackActiveObserverRegistered = NO; _playbackStalled = NO; @@ -869,7 +870,7 @@ - (void)setPaused:(BOOL)paused [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; } - if (@available(iOS 10.0, *) && _automaticallyWaitsToMinimizeStalling) { + if (@available(iOS 10.0, *) && !_automaticallyWaitsToMinimizeStalling) { [_player playImmediatelyAtRate:1.0]; } else { [_player play]; From 4320b56545fe21824b60073c0a0e9684504c15ee Mon Sep 17 00:00:00 2001 From: Jovan Stanimirovic Date: Thu, 22 Aug 2019 11:03:23 +0200 Subject: [PATCH 4/6] bumped version & updated changelog --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48f1b80516..bf3f2593e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +### Version 5.0.1 +* Added support for automaticallyWaitsToMinimizeStalling property (iOS) [#1723](https://github.com/react-native-community/react-native-video/pull/1723) + ### Version 5.0.0 * AndroidX Support diff --git a/package.json b/package.json index 3b2c58e233..7bcb784ef2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-video", - "version": "5.0.0", + "version": "5.0.1", "description": "A