如何正确处理音频中断
How to properly handle audio interruptions?
我创建了一个利用OpenAL进行音频播放的OpenGL 3D游戏,如果在音频设备初始化之前按下"Home"按钮,则会遇到丢失音频的问题。我试图挂接到音频会话中断处理程序,但我的回调从未被调用。无论我是否最小化或最大化我的应用程序。我的"OpenALInterruptionListener"永远不会被调用。
我做错了什么?
AudioSessionInitialize(NULL, NULL, OpenALInterriptionListener, this);
void OpenALInterriptionListener(void * inClientData, UInt32 inInterruptionState)
{
OpenALDevice * device = (OpenALDevice *) inClientData;
if (inInterruptionState == kAudioSessionBeginInterruption)
{
alcSuspendContext(_context);
alcMakeContextCurrent(_context);
AudioSessionSetActive(false);
}
else if (inInterruptionState == kAudioSessionEndInterruption)
{
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(true);
alcMakeContextCurrent(_context);
alcProcessContext(_context);
}
}
请注意,音频中断和 IOS 目前存在问题。 中断通知很好,但结束音频中断通知并不总是有效。 苹果在这方面有一个错误,他们没有回应。
尝试在 alcMakeContextCurrent(( 中使用 NULL。
void OpenALInterriptionListener(void *inClientData, UInt32 inInterruptionState)
{
OpenALDevice * device = (OpenALDevice *) inClientData;
OSStatus nResult;
if( inInterruptionState == kAudioSessionBeginInterruption )
{
alcMakeContextCurrent(NULL);
}
else if( inInterruptionState == kAudioSessionEndInterruption )
{
nResult = AudioSessionSetActive(true);
if( nResult )
{
// "Error setting audio session active"
}
alcMakeContextCurrent( device->GetContext() );
}
}
相关文章:
- 用c++阅读音频
- 为什么这个音频包络不能通过开关的情况?
- FFMpeg库:如何在音频文件中精确查找
- 类成员和中断
- 捕获标准输出以压缩并使用 CTRL-C 中断会给出损坏的 zip 文件
- 需要反转音频步进公式
- 如何在音频处理中使用超能力时间拉伸类
- 我的代码运行良好,但在游戏循环中中断
- 使用带有MCP23017的 pigpio 进行中断读取
- 为什么我在 AVR 中的中断无法正常工作?
- C++新手,想知道如何使用VS code 2019播放音频文件
- 如何暂停插孔音频客户端
- 使用 UDP 中断 while()-循环
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何在 CompleteAsyncIO 中访问 IOMemoryBufferDescriptor,该描述符通过中断 EP
- 如何为伺服电机创建中断或返回值?
- 开关:无外壳中断
- 如何使用中断停止循环?
- 如何以编程方式将音频从任何录制设备路由到任何播放设备
- 如何正确处理音频中断