I'm trying to make a function which stops all sounds in an iOS device, including the sounds of other apps that may run in the background. I think this can be done with audio sessions. Here's the code I came up with so far:
- (void) setUpAudioSessionExlusive
{
AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
OSStatus propertySetError = 0;
UInt32 allowMixing = false;
propertySetError = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);
if (propertySetError)
NSLog(@"Error setting kAudioSessionProperty_OverrideCategoryMixWithOthers: %ld", propertySetError);
// Activate audio session
OSStatus activationResult = 0;
activationResult = AudioSessionSetActive(true);
if (!activationResult)
{
NSLog(@"AudioSession is active");
}
}
However, while this stops the music from the iPod application, it does not stop the sounds of an internet radio app I have. Am I doing something wrong and is it what I'm trying to do possible at all? Huge thanks!