Restoring audio session, after interruption. I'm a bit stuck!

Member
Posts: 129
Joined: 2009.03
Post: #1
Or I could be a 'lot' stuck...

When the clock app's timer goes off, during my app, and after I tap 'Done', no more openAL sounds are playing in my app.

I've been looking through the docs re: restoring audio sessions after interruption, and I've tried coding the c style interruption listener callback, but something's not working. So far, I have..

Code:
void
InterruptionListener(void* inClientData,UInt32 inInterruptionState)
{
    if (inInterruptionState == kAudioSessionBeginInterruption)
    {
        alcMakeContextCurrent(NULL);        
    }
    else if (inInterruptionState == kAudioSessionEndInterruption)
    {
        alcMakeContextCurrent(s_alContext);
    }
}

..which is my callback, and is setup thus..

Code:
AudioSessionInitialize(NULL,NULL,InterruptionListener,0);
AudioSessionSetActive(true);

I'm guessing I need to do more, like restore the audiosession in the callback function? Or there's something else I'm missing?

Any suggestions? Smile

Thanks.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #2
Here's what I (essentially) do in my interrupt callback - seems to work...

Code:
if (interruptionState == kAudioSessionBeginInterruption) {

    alcSuspendContext(txa_alcontext);
    alcMakeContextCurrent(NULL);
    AudioSessionSetActive(false);
            
} else if (interruptionState == kAudioSessionEndInterruption) {
        
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, // etc...
    AudioSessionSetActive(true);
    alcMakeContextCurrent(txa_alcontext);
    alcProcessContext(txa_alcontext);        
}
Quote this message in a reply
Member
Posts: 129
Joined: 2009.03
Post: #3
Works like a charm (perfectly), many thanks Frank.

However, I'm finding that my music is stopping too. I'm using AVAudioPlayer to play MP3s (via the iPhone hardware I hope). Any tips for pausing and resuming music? I guess it's not too difficult, will have a look through the docs in the morning. Smile
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #4
The system will pause AVAudioPlayers for you (and I think as of OS 3.1 it actually resumes them on its own too - can't recall the details). But, you can set up a delegate to handle interruptions on each AVAudioPlayer if you really need too, or just use applicationWillResignActive and applicationDidBecomeActive to make sure the background music stops and restarts as needed.
Quote this message in a reply
Post Reply