floatinghotpot/cordova-plugin-nativeaudio

Change iOS music Category

jvwelzen opened this issue · 0 comments

Hi, I have forked this plugin and made some changes so I can change the music category on iOS using javascript

It's not the best solution so if someone know to get it better, you are welcome ;-)

my simpel solution was to make some extra functions

- (void)pluginInitialize
{
    self.fadeMusic = NO;
    
    
    // we activate the audio session after the options to mix with others is set
    [[AVAudioSession sharedInstance] setActive:NO error:nil];

    // Allows the application to mix its audio with audio from other apps.
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];

    
}
- (void) setCategory:(CDVInvokedUrlCommand *)command {
    
    NSArray* arguments = command.arguments;
    NSString *category = [arguments objectAtIndex:0];
    NSString *options = [arguments objectAtIndex:1];
    AVAudioSessionCategoryOptions optionsOrig = 0;

    if([options isEqualToString: @"AVAudioSessionCategoryOptionMixWithOthers"]){
    optionsOrig = AVAudioSessionCategoryOptionMixWithOthers;
    }
    if([options isEqualToString: @"AVAudioSessionCategoryOptionDuckOthers"]){
    optionsOrig = AVAudioSessionCategoryOptionDuckOthers;
    }
        
    [[AVAudioSession sharedInstance] setCategory:category withOptions:optionsOrig error:nil];
        

    [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
}

https://github.com/jvwelzen/cordova-plugin-nativeaudio