implement automaticallyWaitsToMinimizeStalling on iOS (#49)

* implement automaticallyWaitsToMinimizeStalling on iOS

* Allow automaticallyWaitsToMinimizeStalling to be called before setUrl

Co-authored-by: ryanheise <ryan@ryanheise.com>
This commit is contained in:
Esmond Wong 2020-03-07 08:49:35 +08:00 committed by GitHub
parent f3d9a34b50
commit c79216c818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View file

@ -17,6 +17,7 @@
BOOL _buffering;
id _endObserver;
id _timeObserver;
BOOL _automaticallyWaitsToMinimizeStalling;
}
- (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar playerId:(NSString*)idParam {
@ -37,6 +38,7 @@
_buffering = NO;
_endObserver = 0;
_timeObserver = 0;
_automaticallyWaitsToMinimizeStalling = YES;
__weak __typeof__(self) weakSelf = self;
[_methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
[weakSelf handleMethodCall:call result:result];
@ -66,6 +68,9 @@
} else if ([@"setSpeed" isEqualToString:call.method]) {
[self setSpeed:(float)[args[0] doubleValue]];
result(nil);
} else if ([@"setAutomaticallyWaitsToMinimizeStalling" isEqualToString:call.method]) {
[self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[args[0] boolValue]];
result(nil);
} else if ([@"seek" isEqualToString:call.method]) {
[self seek:[args[0] intValue] result:result];
result(nil);
@ -198,6 +203,9 @@
[_player removeTimeObserver:_timeObserver];
_timeObserver = 0;
}
if (@available(iOS 10.0, *)) {
_player.automaticallyWaitsToMinimizeStalling = _automaticallyWaitsToMinimizeStalling;
}
// TODO: learn about the different ways to define weakSelf.
//__weak __typeof__(self) weakSelf = self;
//typeof(self) __weak weakSelf = self;
@ -301,6 +309,15 @@
}
}
-(void)setAutomaticallyWaitsToMinimizeStalling:(bool)automaticallyWaitsToMinimizeStalling {
_automaticallyWaitsToMinimizeStalling = automaticallyWaitsToMinimizeStalling;
if (@available(iOS 10.0, *)) {
if(_player) {
_player.automaticallyWaitsToMinimizeStalling = automaticallyWaitsToMinimizeStalling;
}
}
}
- (void)seek:(int)position result:(FlutterResult)result {
_seekPos = position;
NSLog(@"seek. enter buffering");