Add setIosCategory
This commit is contained in:
parent
64dc836b7f
commit
02631bfe84
8 changed files with 58 additions and 7 deletions
|
@ -18,13 +18,15 @@
|
|||
id _endObserver;
|
||||
id _timeObserver;
|
||||
BOOL _automaticallyWaitsToMinimizeStalling;
|
||||
BOOL _configuredSession;
|
||||
}
|
||||
|
||||
- (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar playerId:(NSString*)idParam {
|
||||
- (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar playerId:(NSString*)idParam configuredSession:(BOOL)configuredSession {
|
||||
self = [super init];
|
||||
NSAssert(self, @"super init cannot be nil");
|
||||
_registrar = registrar;
|
||||
_playerId = idParam;
|
||||
_configuredSession = configuredSession;
|
||||
_methodChannel = [FlutterMethodChannel
|
||||
methodChannelWithName:[NSMutableString stringWithFormat:@"com.ryanheise.just_audio.methods.%@", _playerId]
|
||||
binaryMessenger:[registrar messenger]];
|
||||
|
@ -285,6 +287,9 @@
|
|||
// TODO: dynamically adjust the lag.
|
||||
//int lag = 6;
|
||||
//int start = [self getCurrentPosition];
|
||||
if (_configuredSession) {
|
||||
[[AVAudioSession sharedInstance] setActive:YES error:nil];
|
||||
}
|
||||
[_player play];
|
||||
if (!@available(macOS 10.12, iOS 10.0, *)) {[self setPlaybackState:playing];}
|
||||
// TODO: convert this Android code to iOS
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#import "JustAudioPlugin.h"
|
||||
#import "AudioPlayer.h"
|
||||
#import "AudioPlayer.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
@implementation JustAudioPlugin {
|
||||
NSObject<FlutterPluginRegistrar>* _registrar;
|
||||
BOOL _configuredSession;
|
||||
}
|
||||
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
||||
|
@ -25,7 +27,23 @@
|
|||
if ([@"init" isEqualToString:call.method]) {
|
||||
NSArray* args = (NSArray*)call.arguments;
|
||||
NSString* playerId = args[0];
|
||||
AudioPlayer* player = [[AudioPlayer alloc] initWithRegistrar:_registrar playerId:playerId];
|
||||
AudioPlayer* player = [[AudioPlayer alloc] initWithRegistrar:_registrar playerId:playerId configuredSession:_configuredSession];
|
||||
result(nil);
|
||||
} else if ([@"setIosCategory" isEqualToString:call.method]) {
|
||||
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];
|
||||
result(nil);
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue