1

I am currently developing an app that needs to play a short audio even when the phone is muted. The following code does play the audio when the phone is not muted, but it does NOT play the audio when the phone IS muted, like I would want it to.

Here is the code:

// set playback settings
self.audioSession = [AVAudioSession sharedInstance];
[self.audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

AudioSessionSetActive(true);
UInt32 property = kAudioSessionProperty_OtherMixableAudioShouldDuck;
AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(property), &property);
OSStatus result = AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(property), &property);
if (result) {
    NSLog(@"error seting property");
}

// set sound file settings
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"baby_crying" ofType:@"mp3"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundId);

AudioServicesPlaySystemSound(soundId);

Please let me know what is wrong with this code.

Jay
  • 21
  • 1
  • 5
  • If the phone is muted the user doesn't want to hear ANY sounds. Just logically with no references I do not think that what you want to do can be done. – 7usam Feb 22 '13 at 23:16
  • 2
    There are ways to do it. Look at the following apps YouTube, Clear Vision, etc. Here is the [apple documentation for it under "Sound"](http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/TechnologyUsage/TechnologyUsage.html#//apple_ref/doc/uid/TP40006556-CH18-SW4) – Jay Feb 22 '13 at 23:20
  • My bad. Try checkin to see if any NSError is being set in the `setCategory:error:` method – 7usam Feb 22 '13 at 23:47

0 Answers0