From 1aa8140127d9d57767739c8564b00c6a8d33030d Mon Sep 17 00:00:00 2001 From: Orhan Mekic Date: Thu, 27 Apr 2023 16:01:09 +0200 Subject: [PATCH] fix (ios): update audio session configuration so audio can play when some other audio is playing at the same time (#369) --- src/ios/CDVSound.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m index aef211e7..7c9c3121 100644 --- a/src/ios/CDVSound.m +++ b/src/ios/CDVSound.m @@ -378,7 +378,13 @@ - (void)startPlayingAudio:(CDVInvokedUrlCommand*)command } NSString* sessionCategory = bPlayAudioWhenScreenIsLocked ? AVAudioSessionCategoryPlayback : AVAudioSessionCategorySoloAmbient; - [self.avSession setCategory:sessionCategory error:&err]; + UIApplicationState state = [UIApplication sharedApplication].applicationState; + if (state == UIApplicationStateBackground) { + [self.avSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&err]; + } else { + [self.avSession setCategory:sessionCategory error:&err]; + } + if (![self.avSession setActive:YES error:&err]) { // other audio with higher priority that does not allow mixing could cause this to fail NSLog(@"Unable to play audio: %@", [err localizedFailureReason]);