added support for automaticallyWaitsToMinimizeStalling property on iOS

This commit is contained in:
Jovan Stanimirovic 2019-08-22 10:10:39 +02:00
parent c29244bf89
commit e3782c4ec6
4 changed files with 20 additions and 1 deletions

View File

@ -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. 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 Platforms: all
#### bufferConfig #### bufferConfig

View File

@ -382,6 +382,7 @@ Video.propTypes = {
poster: PropTypes.string, poster: PropTypes.string,
posterResizeMode: Image.propTypes.resizeMode, posterResizeMode: Image.propTypes.resizeMode,
repeat: PropTypes.bool, repeat: PropTypes.bool,
automaticallyWaitsToMinimizeStalling: PropTypes.bool,
allowsExternalPlayback: PropTypes.bool, allowsExternalPlayback: PropTypes.bool,
selectedAudioTrack: PropTypes.shape({ selectedAudioTrack: PropTypes.shape({
type: PropTypes.string.isRequired, type: PropTypes.string.isRequired,

View File

@ -54,6 +54,7 @@ static int const RCTVideoUnset = -1;
float _rate; float _rate;
float _maxBitRate; float _maxBitRate;
BOOL _automaticallyWaitsToMinimizeStalling;
BOOL _muted; BOOL _muted;
BOOL _paused; BOOL _paused;
BOOL _repeat; BOOL _repeat;
@ -376,6 +377,7 @@ static int const RCTVideoUnset = -1;
_isExternalPlaybackActiveObserverRegistered = YES; _isExternalPlaybackActiveObserverRegistered = YES;
[self addPlayerTimeObserver]; [self addPlayerTimeObserver];
[self setAutomaticallyWaitsToMinimizeStalling:_automaticallyWaitsToMinimizeStalling];
//Perform on next run loop, otherwise onVideoLoadStart is nil //Perform on next run loop, otherwise onVideoLoadStart is nil
if (self.onVideoLoadStart) { if (self.onVideoLoadStart) {
@ -866,7 +868,13 @@ static int const RCTVideoUnset = -1;
} else if([_ignoreSilentSwitch isEqualToString:@"obey"]) { } else if([_ignoreSilentSwitch isEqualToString:@"obey"]) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; [[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]; [_player setRate:_rate];
} }
@ -953,6 +961,12 @@ static int const RCTVideoUnset = -1;
_playerItem.preferredPeakBitRate = maxBitRate; _playerItem.preferredPeakBitRate = maxBitRate;
} }
- (void)setAutomaticallyWaitsToMinimizeStalling:(BOOL)waits
{
_automaticallyWaitsToMinimizeStalling = waits;
_player.automaticallyWaitsToMinimizeStalling = waits;
}
- (void)applyModifiers - (void)applyModifiers
{ {

View File

@ -22,6 +22,7 @@ RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(maxBitRate, float); RCT_EXPORT_VIEW_PROPERTY(maxBitRate, float);
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString); RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL); RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
RCT_EXPORT_VIEW_PROPERTY(automaticallyWaitsToMinimizeStalling, BOOL);
RCT_EXPORT_VIEW_PROPERTY(allowsExternalPlayback, BOOL); RCT_EXPORT_VIEW_PROPERTY(allowsExternalPlayback, BOOL);
RCT_EXPORT_VIEW_PROPERTY(textTracks, NSArray); RCT_EXPORT_VIEW_PROPERTY(textTracks, NSArray);
RCT_EXPORT_VIEW_PROPERTY(selectedTextTrack, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(selectedTextTrack, NSDictionary);