diff --git a/CordovaLib/Classes/CDVSound.m b/CordovaLib/Classes/CDVSound.m index 706ae3093..ce2c3d024 100644 --- a/CordovaLib/Classes/CDVSound.m +++ b/CordovaLib/Classes/CDVSound.m @@ -177,7 +177,14 @@ - (void) startPlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDiction // get the audioSession and set the category to allow Playing when device is locked or ring/silent switch engaged if ([self hasAudioSession]) { NSError* err = nil; - [self.avSession setCategory:AVAudioSessionCategoryPlayback error:nil]; + NSNumber* playAudioWhenScreenIsLocked = [options objectForKey:@"playAudioWhenScreenIsLocked"]; + BOOL bPlayAudioWhenScreenIsLocked = YES; + if (playAudioWhenScreenIsLocked != nil) { + bPlayAudioWhenScreenIsLocked = [playAudioWhenScreenIsLocked boolValue]; + } + + NSString* sessionCategory = bPlayAudioWhenScreenIsLocked? AVAudioSessionCategoryPlayback : AVAudioSessionCategorySoloAmbient; + [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]);