xcode AudioSessionSetProperty 在 iOS 7.0 中已弃用,因此如何设置 kAudioSessionProperty_OverrideCategoryMixWithOthers

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21682502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:38:42  来源:igfitidea点击:

AudioSessionSetProperty deprecated in iOS 7.0 so how set kAudioSessionProperty_OverrideCategoryMixWithOthers

iosiphonexcode

提问by Carm100

Need non deprecated alternate to (btw I think this is still in the current apple docs at link):

极品非过时替代品(顺便说一句,我认为这仍然是在当前苹果文档的链接):

OSStatus propertySetError = 0;
UInt32 allowMixing = true;

propertySetError = AudioSessionSetProperty (
                       kAudioSessionProperty_OverrideCategoryMixWithOthers,  // 1
                       sizeof (allowMixing),                                 // 2
                       &allowMixing                                          // 3
                   );

Thanks;

谢谢;

回答by Tom Harrington

Use AVAudioSession:

使用AVAudioSession

AVAudioSession *session = [AVAudioSession sharedInstance];

NSError *setCategoryError = nil;
if (![session setCategory:AVAudioSessionCategoryPlayback
         withOptions:AVAudioSessionCategoryOptionMixWithOthers
         error:&setCategoryError]) {
    // handle error
}