ILI4S K4RIM ILI4S K4RIM - 1 year ago 88
iOS Question

Stop another app's background audio on iOS

How do I stop background audio from another app?

I have tried

NSError *error;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:&error];


in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options
and
- (void)applicationWillEnterForeground:(UIApplication *) application
but to no effect.

My app plays audio using the The Amazing Audio Engine but does not require background audio itself, so I do not want to add the "audio" key to "Required Device Capabilities" in info.plist

Are there any other solutions?

Answer Source

Got the answer from Michael Tyson of The Amazing Audio Engine over on his forum.

UInt32 allowMixing = NO;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (allowMixing), &allowMixing);

or if you're using The Amazing Audio Engine:
audioController.allowMixingWithOtherApps = NO;

(Seems like this should be set to NO by default depending on which audio session you use, however that was not the case with The Amazing Audio Engine)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download