1

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!

AakashM
  • 62,551
  • 17
  • 151
  • 186
cpprulez
  • 896
  • 2
  • 9
  • 21
  • Its not possible, but you can encourage your users to enable [airplane mode](http://stackoverflow.com/questions/6284402/how-to-disable-ios-system-sounds). – live87 Aug 05 '11 at 07:21
  • Just thinking out loud. You could play a silent audio file and set the session to AVAudioSessionCategorySoloAmbient. This will pause iPod, but not sure about any other ambient sounds. – Miha Hribar Aug 05 '11 at 08:00
  • Thanks, Miha :) I tried it, but it didn't stop the radio sound... :( – cpprulez Aug 05 '11 at 08:31

0 Answers0