Skip to content

Commit

Permalink
Fixes CB-906 - Hardware mute button doesn't effect Media API playback
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron committed Jun 18, 2012
1 parent f97d461 commit b3177d2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CordovaLib/Classes/CDVSound.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit b3177d2

Please sign in to comment.