4
我做了一个iPhone应用程序,它使用OpenAL播放很多声音。 这些声音是在MP3中,很重(超过1mn),我把它们流(每个声音2个缓冲区)以便使用更少的内存。 要管理中断,我用这个代码:openAL流媒体&中断
在OpenALSupport.c文件:
//used to disable openAL during a call
void openALInterruptionListener (void *inClientData, UInt32 inInterruptionState)
{
if (inInterruptionState == kAudioSessionBeginInterruption)
{
alcMakeContextCurrent (NULL);
}
}
//used to restore openAL after a call
void restoreOpenAL(void* a_context)
{
alcMakeContextCurrent(a_context);
}
在我SoundManager.m文件:
- (void) restoreOpenAL
{
restoreOpenAL(mContext);
}
//OPENAL initialization
- (bool) initOpenAL
{
// Initialization
mDevice = alcOpenDevice(NULL);
if (mDevice) {
...
// use the device to make a context
mContext=alcCreateContext(mDevice,NULL);
// set my context to the currently active one
alcMakeContextCurrent(mContext);
AudioSessionInitialize (NULL, NULL, openALInterruptionListener, mContext);
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: &setCategoryError];
...
}
最后在我的AppDelegate:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[CSoundManager getInstance] restoreOpenAL];
...
}
用这种方法,声音在呼叫后回来,但流程似乎是pl随机对话。 有没有一种管理音频流中断的特定方法?我没有找到任何有关这方面的文章。
感谢您的帮助。
总的想法是非常有帮助,谢谢。但是在其中一种情况下,位置/ oldPosition赋值不是交换的吗? – 2014-10-13 10:08:09