iOS/macOS implementation of platform interface.
This commit is contained in:
parent
7a95e995f1
commit
13e257e80e
|
@ -84,64 +84,48 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||||
NSArray* args = (NSArray*)call.arguments;
|
NSDictionary *request = (NSDictionary *)call.arguments;
|
||||||
if ([@"load" isEqualToString:call.method]) {
|
if ([@"load" isEqualToString:call.method]) {
|
||||||
[self load:args[0] result:result];
|
[self load:request[@"audioSource"] result:result];
|
||||||
} else if ([@"play" isEqualToString:call.method]) {
|
} else if ([@"play" isEqualToString:call.method]) {
|
||||||
[self play:result];
|
[self play:result];
|
||||||
} else if ([@"pause" isEqualToString:call.method]) {
|
} else if ([@"pause" isEqualToString:call.method]) {
|
||||||
[self pause];
|
[self pause];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"setVolume" isEqualToString:call.method]) {
|
} else if ([@"setVolume" isEqualToString:call.method]) {
|
||||||
[self setVolume:(float)[args[0] doubleValue]];
|
[self setVolume:(float)[request[@"volume"] doubleValue]];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"setSpeed" isEqualToString:call.method]) {
|
} else if ([@"setSpeed" isEqualToString:call.method]) {
|
||||||
[self setSpeed:(float)[args[0] doubleValue]];
|
[self setSpeed:(float)[request[@"speed"] doubleValue]];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"setLoopMode" isEqualToString:call.method]) {
|
} else if ([@"setLoopMode" isEqualToString:call.method]) {
|
||||||
[self setLoopMode:[args[0] intValue]];
|
[self setLoopMode:[request[@"loopMode"] intValue]];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"setShuffleModeEnabled" isEqualToString:call.method]) {
|
} else if ([@"setShuffleMode" isEqualToString:call.method]) {
|
||||||
[self setShuffleModeEnabled:(BOOL)[args[0] boolValue]];
|
[self setShuffleModeEnabled:(BOOL)([request[@"shuffleMode"] intValue] == 1)];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"setAutomaticallyWaitsToMinimizeStalling" isEqualToString:call.method]) {
|
} else if ([@"setAutomaticallyWaitsToMinimizeStalling" isEqualToString:call.method]) {
|
||||||
[self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[args[0] boolValue]];
|
[self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[request[@"enabled"] boolValue]];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"seek" isEqualToString:call.method]) {
|
} else if ([@"seek" isEqualToString:call.method]) {
|
||||||
CMTime position = args[0] == [NSNull null] ? kCMTimePositiveInfinity : CMTimeMake([args[0] intValue], 1000);
|
CMTime position = request[@"position"] == [NSNull null] ? kCMTimePositiveInfinity : CMTimeMake([request[@"position"] longLongValue], 1000000);
|
||||||
[self seek:position index:args[1] completionHandler:^(BOOL finished) {
|
[self seek:position index:request[@"index"] completionHandler:^(BOOL finished) {
|
||||||
result(nil);
|
result(@{});
|
||||||
}];
|
}];
|
||||||
result(nil);
|
|
||||||
} else if ([@"dispose" isEqualToString:call.method]) {
|
} else if ([@"dispose" isEqualToString:call.method]) {
|
||||||
[self dispose];
|
[self dispose];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"concatenating.add" isEqualToString:call.method]) {
|
} else if ([@"concatenatingInsertAll" isEqualToString:call.method]) {
|
||||||
[self concatenatingAdd:(NSString*)args[0] source:(NSDictionary*)args[1]];
|
[self concatenatingInsertAll:(NSString *)request[@"id"] index:[request[@"index"] intValue] sources:(NSArray *)request[@"children"]];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"concatenating.insert" isEqualToString:call.method]) {
|
} else if ([@"concatenatingRemoveRange" isEqualToString:call.method]) {
|
||||||
[self concatenatingInsert:(NSString*)args[0] index:[args[1] intValue] source:(NSDictionary*)args[2]];
|
[self concatenatingRemoveRange:(NSString *)request[@"id"] start:[request[@"startIndex"] intValue] end:[request[@"endIndex"] intValue]];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"concatenating.addAll" isEqualToString:call.method]) {
|
} else if ([@"concatenatingMove" isEqualToString:call.method]) {
|
||||||
[self concatenatingAddAll:(NSString*)args[0] sources:(NSArray*)args[1]];
|
[self concatenatingMove:(NSString *)request[@"id"] currentIndex:[request[@"currentIndex"] intValue] newIndex:[request[@"newIndex"] intValue]];
|
||||||
result(nil);
|
result(@{});
|
||||||
} else if ([@"concatenating.insertAll" isEqualToString:call.method]) {
|
|
||||||
[self concatenatingInsertAll:(NSString*)args[0] index:[args[1] intValue] sources:(NSArray*)args[2]];
|
|
||||||
result(nil);
|
|
||||||
} else if ([@"concatenating.removeAt" isEqualToString:call.method]) {
|
|
||||||
[self concatenatingRemoveAt:(NSString*)args[0] index:[args[1] intValue]];
|
|
||||||
result(nil);
|
|
||||||
} else if ([@"concatenating.removeRange" isEqualToString:call.method]) {
|
|
||||||
[self concatenatingRemoveRange:(NSString*)args[0] start:[args[1] intValue] end:[args[2] intValue]];
|
|
||||||
result(nil);
|
|
||||||
} else if ([@"concatenating.move" isEqualToString:call.method]) {
|
|
||||||
[self concatenatingMove:(NSString*)args[0] currentIndex:[args[1] intValue] newIndex:[args[2] intValue]];
|
|
||||||
result(nil);
|
|
||||||
} else if ([@"concatenating.clear" isEqualToString:call.method]) {
|
|
||||||
[self concatenatingClear:(NSString*)args[0]];
|
|
||||||
result(nil);
|
|
||||||
} else if ([@"setAndroidAudioAttributes" isEqualToString:call.method]) {
|
} else if ([@"setAndroidAudioAttributes" isEqualToString:call.method]) {
|
||||||
result(nil);
|
result(@{});
|
||||||
} else {
|
} else {
|
||||||
result(FlutterMethodNotImplemented);
|
result(FlutterMethodNotImplemented);
|
||||||
}
|
}
|
||||||
|
@ -318,13 +302,13 @@
|
||||||
if (!_eventSink) return;
|
if (!_eventSink) return;
|
||||||
_eventSink(@{
|
_eventSink(@{
|
||||||
@"processingState": @(_processingState),
|
@"processingState": @(_processingState),
|
||||||
@"updatePosition": @(_updatePosition),
|
@"updatePosition": @((long long)1000 * _updatePosition),
|
||||||
@"updateTime": @(_updateTime),
|
@"updateTime": @(_updateTime),
|
||||||
// TODO: buffer position
|
// TODO: buffer position
|
||||||
@"bufferedPosition": @(_updatePosition),
|
@"bufferedPosition": @((long long)1000 * _updatePosition),
|
||||||
// TODO: Icy Metadata
|
// TODO: Icy Metadata
|
||||||
@"icyMetadata": [NSNull null],
|
@"icyMetadata": [NSNull null],
|
||||||
@"duration": @([self getDuration]),
|
@"duration": @((long long)1000 * [self getDuration]),
|
||||||
@"currentIndex": @(_index),
|
@"currentIndex": @(_index),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -411,17 +395,17 @@
|
||||||
return [[UriAudioSource alloc] initWithId:data[@"id"] uri:data[@"uri"]];
|
return [[UriAudioSource alloc] initWithId:data[@"id"] uri:data[@"uri"]];
|
||||||
} else if ([@"concatenating" isEqualToString:type]) {
|
} else if ([@"concatenating" isEqualToString:type]) {
|
||||||
return [[ConcatenatingAudioSource alloc] initWithId:data[@"id"]
|
return [[ConcatenatingAudioSource alloc] initWithId:data[@"id"]
|
||||||
audioSources:[self decodeAudioSources:data[@"audioSources"]]];
|
audioSources:[self decodeAudioSources:data[@"children"]]];
|
||||||
} else if ([@"clipping" isEqualToString:type]) {
|
} else if ([@"clipping" isEqualToString:type]) {
|
||||||
return [[ClippingAudioSource alloc] initWithId:data[@"id"]
|
return [[ClippingAudioSource alloc] initWithId:data[@"id"]
|
||||||
audioSource:[self decodeAudioSource:data[@"audioSource"]]
|
audioSource:[self decodeAudioSource:data[@"child"]]
|
||||||
start:data[@"start"]
|
start:data[@"start"]
|
||||||
end:data[@"end"]];
|
end:data[@"end"]];
|
||||||
} else if ([@"looping" isEqualToString:type]) {
|
} else if ([@"looping" isEqualToString:type]) {
|
||||||
NSMutableArray *childSources = [NSMutableArray new];
|
NSMutableArray *childSources = [NSMutableArray new];
|
||||||
int count = [data[@"count"] intValue];
|
int count = [data[@"count"] intValue];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
[childSources addObject:[self decodeAudioSource:data[@"audioSource"]]];
|
[childSources addObject:[self decodeAudioSource:data[@"child"]]];
|
||||||
}
|
}
|
||||||
return [[LoopingAudioSource alloc] initWithId:data[@"id"] audioSources:childSources];
|
return [[LoopingAudioSource alloc] initWithId:data[@"id"] audioSources:childSources];
|
||||||
} else {
|
} else {
|
||||||
|
@ -583,7 +567,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_player.currentItem.status == AVPlayerItemStatusReadyToPlay) {
|
if (_player.currentItem.status == AVPlayerItemStatusReadyToPlay) {
|
||||||
_loadResult(@([self getDuration]));
|
_loadResult(@{@"duration": @((long long)1000 * [self getDuration])});
|
||||||
_loadResult = nil;
|
_loadResult = nil;
|
||||||
} else {
|
} else {
|
||||||
// We send result after the playerItem is ready in observeValueForKeyPath.
|
// We send result after the playerItem is ready in observeValueForKeyPath.
|
||||||
|
@ -724,7 +708,7 @@
|
||||||
}
|
}
|
||||||
[self broadcastPlaybackEvent];
|
[self broadcastPlaybackEvent];
|
||||||
if (_loadResult) {
|
if (_loadResult) {
|
||||||
_loadResult(@([self getDuration]));
|
_loadResult(@{@"duration": @((long long)1000 * [self getDuration])});
|
||||||
_loadResult = nil;
|
_loadResult = nil;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -911,7 +895,7 @@
|
||||||
if (result) {
|
if (result) {
|
||||||
if (_playResult) {
|
if (_playResult) {
|
||||||
NSLog(@"INTERRUPTING PLAY");
|
NSLog(@"INTERRUPTING PLAY");
|
||||||
_playResult(nil);
|
_playResult(@{});
|
||||||
}
|
}
|
||||||
_playResult = result;
|
_playResult = result;
|
||||||
}
|
}
|
||||||
|
@ -939,7 +923,7 @@
|
||||||
[self broadcastPlaybackEvent];
|
[self broadcastPlaybackEvent];
|
||||||
if (_playResult) {
|
if (_playResult) {
|
||||||
NSLog(@"PLAY FINISHED DUE TO PAUSE");
|
NSLog(@"PLAY FINISHED DUE TO PAUSE");
|
||||||
_playResult(nil);
|
_playResult(@{});
|
||||||
_playResult = nil;
|
_playResult = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -950,7 +934,7 @@
|
||||||
[self broadcastPlaybackEvent];
|
[self broadcastPlaybackEvent];
|
||||||
if (_playResult) {
|
if (_playResult) {
|
||||||
NSLog(@"PLAY FINISHED DUE TO COMPLETE");
|
NSLog(@"PLAY FINISHED DUE TO COMPLETE");
|
||||||
_playResult(nil);
|
_playResult(@{});
|
||||||
_playResult = nil;
|
_playResult = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
self = [super initWithId:sid];
|
self = [super initWithId:sid];
|
||||||
NSAssert(self, @"super init cannot be nil");
|
NSAssert(self, @"super init cannot be nil");
|
||||||
_audioSource = audioSource;
|
_audioSource = audioSource;
|
||||||
_start = start == [NSNull null] ? kCMTimeZero : CMTimeMake([start intValue], 1000);
|
_start = start == [NSNull null] ? kCMTimeZero : CMTimeMake([start longLongValue], 1000000);
|
||||||
_end = end == [NSNull null] ? kCMTimeInvalid : CMTimeMake([end intValue], 1000);
|
_end = end == [NSNull null] ? kCMTimeInvalid : CMTimeMake([end longLongValue], 1000000);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,28 +25,10 @@
|
||||||
|
|
||||||
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
||||||
if ([@"init" isEqualToString:call.method]) {
|
if ([@"init" isEqualToString:call.method]) {
|
||||||
NSArray* args = (NSArray*)call.arguments;
|
NSDictionary *request = (NSDictionary *)call.arguments;
|
||||||
NSString* playerId = args[0];
|
NSString *playerId = request[@"id"];
|
||||||
/*AudioPlayer* player =*/ [[AudioPlayer alloc] initWithRegistrar:_registrar playerId:playerId configuredSession:_configuredSession];
|
/*AudioPlayer* player =*/ [[AudioPlayer alloc] initWithRegistrar:_registrar playerId:playerId configuredSession:_configuredSession];
|
||||||
result(nil);
|
result(nil);
|
||||||
} else if ([@"setIosCategory" isEqualToString:call.method]) {
|
|
||||||
#if TARGET_OS_IPHONE
|
|
||||||
NSNumber* categoryIndex = (NSNumber*)call.arguments;
|
|
||||||
AVAudioSessionCategory category = nil;
|
|
||||||
switch (categoryIndex.integerValue) {
|
|
||||||
case 0: category = AVAudioSessionCategoryAmbient; break;
|
|
||||||
case 1: category = AVAudioSessionCategorySoloAmbient; break;
|
|
||||||
case 2: category = AVAudioSessionCategoryPlayback; break;
|
|
||||||
case 3: category = AVAudioSessionCategoryRecord; break;
|
|
||||||
case 4: category = AVAudioSessionCategoryPlayAndRecord; break;
|
|
||||||
case 5: category = AVAudioSessionCategoryMultiRoute; break;
|
|
||||||
}
|
|
||||||
if (category) {
|
|
||||||
_configuredSession = YES;
|
|
||||||
}
|
|
||||||
[[AVAudioSession sharedInstance] setCategory:category error:nil];
|
|
||||||
#endif
|
|
||||||
result(nil);
|
|
||||||
} else {
|
} else {
|
||||||
result(FlutterMethodNotImplemented);
|
result(FlutterMethodNotImplemented);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue