2012-05-16 141 views
12

我已經創建了一個OpenGL 3D遊戲,利用OpenAL進行音頻播放,並且在音頻設備初始化之前按下「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); 
    } 
} 

回答

0

嘗試在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()); 
    } 
} 
+0

[http://benbritten.com/2009/02/02/restarting-openal-after-application-interruption-on-the-iphone/](http://benbritten.com/2009/02/02/重新啓動 - OpenAL的,後應用程序中斷-ON-THE-iphone /) – james82345

1

請注意,目前有帶音頻中斷和IOS的問題。中斷通知很好,但結束音頻中斷通知不總是工作。在這方面有一個蘋果的問題,他們沒有迴應。