Stop Background audio while starting

こ雲淡風輕ζ 提交于 2019-12-02 07:24:58

Have a look at AVAudioSession class and AVAudioSession programming guide by Apple. This will hopefully steer you in the right direction.

To stop background audio when your application starts set your audio session to a non-mixable category and mode then set active.

If you don't configure an audio session your application will get the default session which in your case is not what you're after.

Try this in you applicationDelegates method - (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");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!