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]);