Skip to content

Commit 052ef65

Browse files
CHaNGeTeBeau Ner
authored and
Beau Ner
committed
Merge pull request TheWidlarzGroup#1723 from blitzcrank/master
Added support for automaticallyWaitsToMinimizeStalling property on iOS (rebased from commit 59be8b5)
1 parent e73a114 commit 052ef65

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Changelog
22

3+
### next
4+
* Added support for automaticallyWaitsToMinimizeStalling property (iOS) [#1723](https://github.com/react-native-community/react-native-video/pull/1723)
5+
36
### Version 5.0.2
47
* Fix crash when RCTVideo's superclass doesn't observe the keyPath 'frame' (iOS) [#1720](https://github.com/react-native-community/react-native-video/pull/1720)
58

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ var styles = StyleSheet.create({
292292
### Configurable props
293293
* [allowsExternalPlayback](#allowsexternalplayback)
294294
* [audioOnly](#audioonly)
295+
* [automaticallyWaitsToMinimizeStalling](#automaticallyWaitsToMinimizeStalling)
295296
* [bufferConfig](#bufferconfig)
296297
* [controls](#controls)
297298
* [filter](#filter)
@@ -370,6 +371,13 @@ For this to work, the poster prop must be set.
370371

371372
Platforms: all
372373

374+
#### automaticallyWaitsToMinimizeStalling
375+
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
376+
* **false** - Immediately starts playback
377+
* **true (default)** - Delays playback in order to minimize stalling
378+
379+
Platforms: iOS
380+
373381
#### bufferConfig
374382
Adjust the buffer settings. This prop takes an object with one or more of the properties listed below.
375383

Video.js

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ Video.propTypes = {
428428
poster: PropTypes.string,
429429
posterResizeMode: Image.propTypes.resizeMode,
430430
repeat: PropTypes.bool,
431+
automaticallyWaitsToMinimizeStalling: PropTypes.bool,
431432
allowsExternalPlayback: PropTypes.bool,
432433
selectedAudioTrack: PropTypes.shape({
433434
type: PropTypes.string.isRequired,

ios/Video/RCTVideo.m

+18-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ @implementation RCTVideo
6767
float _rate;
6868
float _maxBitRate;
6969

70+
BOOL _automaticallyWaitsToMinimizeStalling;
7071
BOOL _muted;
7172
BOOL _paused;
7273
BOOL _repeat;
@@ -106,6 +107,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
106107
inView = true; // ZEROLABS
107108
_separateAudioTrack = YES; // ZEROLABS
108109

110+
_automaticallyWaitsToMinimizeStalling = YES;
109111
_playbackRateObserverRegistered = NO;
110112
_isExternalPlaybackActiveObserverRegistered = NO;
111113
_playbackStalled = NO;
@@ -565,6 +567,9 @@ - (void)crankVideo2 {
565567
_isExternalPlaybackActiveObserverRegistered = YES;
566568

567569
[self addPlayerTimeObserver];
570+
if (@available(iOS 10.0, *)) {
571+
[self setAutomaticallyWaitsToMinimizeStalling:_automaticallyWaitsToMinimizeStalling];
572+
}
568573

569574
//Perform on next run loop, otherwise onVideoLoadStart is nil
570575
if (self.onVideoLoadStart) {
@@ -1312,7 +1317,13 @@ - (void)setPaused:(BOOL)paused
13121317
} else if([_ignoreSilentSwitch isEqualToString:@"obey"]) {
13131318
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
13141319
}
1315-
[_player play];
1320+
1321+
if (@available(iOS 10.0, *) && !_automaticallyWaitsToMinimizeStalling) {
1322+
[_player playImmediatelyAtRate:1.0];
1323+
} else {
1324+
[_player play];
1325+
[_player setRate:_rate];
1326+
}
13161327
[_player setRate:_rate];
13171328
}
13181329

@@ -1399,6 +1410,12 @@ - (void)setMaxBitRate:(float) maxBitRate {
13991410
_playerItem.preferredPeakBitRate = maxBitRate;
14001411
}
14011412

1413+
- (void)setAutomaticallyWaitsToMinimizeStalling:(BOOL)waits
1414+
{
1415+
_automaticallyWaitsToMinimizeStalling = waits;
1416+
_player.automaticallyWaitsToMinimizeStalling = waits;
1417+
}
1418+
14021419

14031420
- (void)applyModifiers
14041421
{

ios/Video/RCTVideoManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ - (dispatch_queue_t)methodQueue
2929
RCT_EXPORT_VIEW_PROPERTY(maxBitRate, float);
3030
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
3131
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
32+
RCT_EXPORT_VIEW_PROPERTY(automaticallyWaitsToMinimizeStalling, BOOL);
3233
RCT_EXPORT_VIEW_PROPERTY(allowsExternalPlayback, BOOL);
3334
RCT_EXPORT_VIEW_PROPERTY(textTracks, NSArray);
3435
RCT_EXPORT_VIEW_PROPERTY(selectedTextTrack, NSDictionary);

0 commit comments

Comments
 (0)