如何妥善处理音频中断? [英] How to properly handle audio interruptions?

查看:290
本文介绍了如何妥善处理音频中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建使用的OpenAL音频播放和experienceing失去音频如果主页按钮越来越之前,音频设备pssed $ P $是越来越初始化的问题OpenGL的3D游戏。我试图挂钩到音频会话中断处理程序,但我的回调是永远不会获取调用。无论我是否最小化或最大化我的申请。我的OpenALInterruptionListener永远不会获取调用。

我在做什么错了?

  AudioSessionInitialize(NULL,NULL,OpenALInterriptionListener,这一点);无效OpenALInterriptionListener(无效* inClientData,UInt32的inInterruptionState)
{
    OpenALDevice *设备=(OpenALDevice *)inClientData;    如果(inInterruptionState == kAudioSessionBeginInterruption)
    {
          alcSuspendContext(_context);
          alcMakeContextCurrent(_context);
          AudioSessionSetActive(假);
    }
    否则,如果(inInterruptionState == kAudioSessionEndInterruption)
    {
          UInt32的sessionCategory = kAudioSessionCategory_AmbientSound;
          AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,sizeof的(sessionCategory),放大器; sessionCategory);
          AudioSessionSetActive(真);
          alcMakeContextCurrent(_context);
          alcProcessContext(_context);
    }
}


解决方案

请注意,目前有带音频中断和IOS的问题。中断的通知都很好,但最终音频中断通知并不总是工作。有关于这个错误变成苹果和他们没有回应。

I've created a OpenGL 3D game utilizing OpenAL for audio playback and experienceing a problem of losing audio if "Home" button is getting pressed before audio device is getting initialized. I tried to hook up to audio session interrupt handler, but my callback is never getting called. No matter if I minimize or maximize my application. My "OpenALInterruptionListener" is never getting called.

What am I doing wrong?

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);
    }
}

解决方案

Please note that there are currently issues with Audio Interruptions and IOS. Interruption notifications are fine, but end Audio Interruptions Notifications do not always work. There is a bug into Apple on this and they have not responded.

这篇关于如何妥善处理音频中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆