cordova-plugin-nativeaudio
cordova-plugin-nativeaudio copied to clipboard
Ambient audio (AVAudioSessionCategoryAmbient)
I'm trying to get my App to play short sounds without interrupting the native audio player (if the user if playing music). The only way I can get this to work is to swap NativeAudio.m line 47
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
with
[session setCategory:AVAudioSessionCategoryAmbient error:nil];
Is there a way to set this from the JS? If not is this something that can be implemented easily? Failing that, is there any reason I shouldn't change that line number?
P.s. Thanks for the Plugin!
This is what you want :
[session setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:nil];
Per @pmwisdom, if you turn pluginInitialize into this you can play music and still emit sounds from your app at the same time:
- (void)pluginInitialize
{
self.fadeMusic = NO;
AudioSessionInitialize(NULL, NULL, nil , nil);
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
// Allows the application to mix its audio with audio from other apps.
if (![session setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:&setCategoryError]) {
NSLog (@"Error setting audio session category.");
return;
}
}