[英]Stop another app's background audio on iOS
如何停止其他应用程序的背景音频?
我努力了
NSError *error;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:&error];
在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options
和- (void)applicationWillEnterForeground:(UIApplication *) application
但无效。
我的应用程序使用The Amazing Audio Engine播放音频,但本身不需要背景音频,因此我不想在info.plist的“ Required Device Capabilities”中添加“ audio”键
还有其他解决方案吗?
在论坛上得到了The Amazing Audio Engine的Michael Tyson的解答 。
UInt32 allowMixing = NO;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (allowMixing), &allowMixing);
或者,如果您使用的是The Amazing Audio Engine:
audioController.allowMixingWithOtherApps = NO;
(根据您所使用的音频会话,默认情况下,似乎应将此默认设置为NO,但是The Amazing Audio Engine并非如此)
我在iOS应用程序中遇到了类似的问题,并通过“ Bamsworld”的解决方案解决了该问题。 检查链接以获取详细信息。
解决方案:在您的appDelegate中尝试以下操作:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// set audio session category AVAudioSessionCategoryPlayAndRecord with no options
success = [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error:nil];
if (!success) {
NSLog(@"setCategoryError");
}
// set audio session mode to default
success = [[AVAudioSession sharedInstance] setMode:AVAudioSessionModeDefault error:nil];
if (!success) {
NSLog(@"setModeError");
}
// activate audio session
success = [[AVAudioSession sharedInstance] setActive:YES error:nil];
if (!success) {
NSLog(@"activationError");
}
// ... etc.
}
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:nil];
解决这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.