From e3782c4ec612701e69136cb613f4cb203836ae55 Mon Sep 17 00:00:00 2001 From: Jovan Stanimirovic Date: Thu, 22 Aug 2019 10:10:39 +0200 Subject: [PATCH] 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 2c40b188..9bb76c8a 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 474d7b26..e5d56729 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 4710afaa..b4a3f063 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -54,6 +54,7 @@ static int const RCTVideoUnset = -1; float _rate; float _maxBitRate; + BOOL _automaticallyWaitsToMinimizeStalling; BOOL _muted; BOOL _paused; BOOL _repeat; @@ -376,6 +377,7 @@ static int const RCTVideoUnset = -1; _isExternalPlaybackActiveObserverRegistered = YES; [self addPlayerTimeObserver]; + [self setAutomaticallyWaitsToMinimizeStalling:_automaticallyWaitsToMinimizeStalling]; //Perform on next run loop, otherwise onVideoLoadStart is nil if (self.onVideoLoadStart) { @@ -866,7 +868,13 @@ static int const RCTVideoUnset = -1; } 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 @@ static int const RCTVideoUnset = -1; _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 1614eab1..7233646f 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -22,6 +22,7 @@ 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(automaticallyWaitsToMinimizeStalling, BOOL); RCT_EXPORT_VIEW_PROPERTY(allowsExternalPlayback, BOOL); RCT_EXPORT_VIEW_PROPERTY(textTracks, NSArray); RCT_EXPORT_VIEW_PROPERTY(selectedTextTrack, NSDictionary);