From b3177d223dfd10245e7021cdd06901476a351415 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Mon, 18 Jun 2012 15:32:20 -0700 Subject: [PATCH] Fixes CB-906 - Hardware mute button doesn't effect Media API playback --- CordovaLib/Classes/CDVSound.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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]);