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.