AudioSession已弃用,如何在不中断iOS音乐的情况下播放声音?

时间:2014-07-11 07:23:40

标签: ios iphone objective-c xcode

OSStatus e;
// initialize the audio session. don't know if you already do this.
e = AudioSessionInitialize(NULL, NULL, NULL, NULL);
if (e)
{
    NSLog(@"failed to start audiosession: %i", (int)e);

}
// ***********************************************************
// * THIS IS THE CODE THAT MAKES OTHER AUDIO BE ABLE TO PLAY *
// ***********************************************************
UInt32 category = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
// ***********************************************************
// *                         HOORAY                          *
// ***********************************************************
// activate the audio session. don't know if you already do this.
e = AudioSessionSetActive(YES);
if (e)
{
    NSLog(@"failed to make audiosession active: %i", (int)e);
}

这是我用来在我的游戏中播放声音而不会在后台中断音乐的代码。但是,现在大多数都被弃用了。我在iOS 7中用什么替换它?

0 个答案:

没有答案