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:
parent
f3d9a34b50
commit
c79216c818
|
@ -17,6 +17,7 @@
|
||||||
BOOL _buffering;
|
BOOL _buffering;
|
||||||
id _endObserver;
|
id _endObserver;
|
||||||
id _timeObserver;
|
id _timeObserver;
|
||||||
|
BOOL _automaticallyWaitsToMinimizeStalling;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar playerId:(NSString*)idParam {
|
- (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar playerId:(NSString*)idParam {
|
||||||
|
@ -37,6 +38,7 @@
|
||||||
_buffering = NO;
|
_buffering = NO;
|
||||||
_endObserver = 0;
|
_endObserver = 0;
|
||||||
_timeObserver = 0;
|
_timeObserver = 0;
|
||||||
|
_automaticallyWaitsToMinimizeStalling = YES;
|
||||||
__weak __typeof__(self) weakSelf = self;
|
__weak __typeof__(self) weakSelf = self;
|
||||||
[_methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
[_methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
||||||
[weakSelf handleMethodCall:call result:result];
|
[weakSelf handleMethodCall:call result:result];
|
||||||
|
@ -66,6 +68,9 @@
|
||||||
} else if ([@"setSpeed" isEqualToString:call.method]) {
|
} else if ([@"setSpeed" isEqualToString:call.method]) {
|
||||||
[self setSpeed:(float)[args[0] doubleValue]];
|
[self setSpeed:(float)[args[0] doubleValue]];
|
||||||
result(nil);
|
result(nil);
|
||||||
|
} else if ([@"setAutomaticallyWaitsToMinimizeStalling" isEqualToString:call.method]) {
|
||||||
|
[self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[args[0] boolValue]];
|
||||||
|
result(nil);
|
||||||
} else if ([@"seek" isEqualToString:call.method]) {
|
} else if ([@"seek" isEqualToString:call.method]) {
|
||||||
[self seek:[args[0] intValue] result:result];
|
[self seek:[args[0] intValue] result:result];
|
||||||
result(nil);
|
result(nil);
|
||||||
|
@ -198,6 +203,9 @@
|
||||||
[_player removeTimeObserver:_timeObserver];
|
[_player removeTimeObserver:_timeObserver];
|
||||||
_timeObserver = 0;
|
_timeObserver = 0;
|
||||||
}
|
}
|
||||||
|
if (@available(iOS 10.0, *)) {
|
||||||
|
_player.automaticallyWaitsToMinimizeStalling = _automaticallyWaitsToMinimizeStalling;
|
||||||
|
}
|
||||||
// TODO: learn about the different ways to define weakSelf.
|
// TODO: learn about the different ways to define weakSelf.
|
||||||
//__weak __typeof__(self) weakSelf = self;
|
//__weak __typeof__(self) weakSelf = self;
|
||||||
//typeof(self) __weak 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 {
|
- (void)seek:(int)position result:(FlutterResult)result {
|
||||||
_seekPos = position;
|
_seekPos = position;
|
||||||
NSLog(@"seek. enter buffering");
|
NSLog(@"seek. enter buffering");
|
||||||
|
|
|
@ -83,6 +83,8 @@ class AudioPlayer {
|
||||||
|
|
||||||
double _speed = 1.0;
|
double _speed = 1.0;
|
||||||
|
|
||||||
|
bool _automaticallyWaitsToMinimizeStalling = true;
|
||||||
|
|
||||||
File _cacheFile;
|
File _cacheFile;
|
||||||
|
|
||||||
/// Creates an [AudioPlayer].
|
/// Creates an [AudioPlayer].
|
||||||
|
@ -158,6 +160,10 @@ class AudioPlayer {
|
||||||
/// The current speed of the player.
|
/// The current speed of the player.
|
||||||
double get speed => _speed;
|
double get speed => _speed;
|
||||||
|
|
||||||
|
/// Whether the player should automatically delay playback in order to minimize stalling. (iOS 10.0 or later only)
|
||||||
|
bool get automaticallyWaitsToMinimizeStalling =>
|
||||||
|
_automaticallyWaitsToMinimizeStalling;
|
||||||
|
|
||||||
/// Loads audio media from a URL and completes with the duration of that
|
/// Loads audio media from a URL and completes with the duration of that
|
||||||
/// audio, or null if this call was interrupted by another call so [setUrl],
|
/// audio, or null if this call was interrupted by another call so [setUrl],
|
||||||
/// [setFilePath] or [setAsset].
|
/// [setFilePath] or [setAsset].
|
||||||
|
@ -261,6 +267,16 @@ class AudioPlayer {
|
||||||
await _invokeMethod('setSpeed', [speed]);
|
await _invokeMethod('setSpeed', [speed]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets automaticallyWaitsToMinimizeStalling for AVPlayer in iOS 10.0 or later, defaults to true.
|
||||||
|
/// Has no effect on Android clients
|
||||||
|
Future<void> setAutomaticallyWaitsToMinimizeStalling(
|
||||||
|
final bool automaticallyWaitsToMinimizeStalling) async {
|
||||||
|
_automaticallyWaitsToMinimizeStalling =
|
||||||
|
automaticallyWaitsToMinimizeStalling;
|
||||||
|
await _invokeMethod('setAutomaticallyWaitsToMinimizeStalling',
|
||||||
|
[automaticallyWaitsToMinimizeStalling]);
|
||||||
|
}
|
||||||
|
|
||||||
/// Seeks to a particular position. It is legal to invoke this method from
|
/// Seeks to a particular position. It is legal to invoke this method from
|
||||||
/// any state except for [AudioPlaybackState.none] and
|
/// any state except for [AudioPlaybackState.none] and
|
||||||
/// [AudioPlaybackState.connecting].
|
/// [AudioPlaybackState.connecting].
|
||||||
|
|
Loading…
Reference in New Issue