Audio Interrupt Handling

I am developing an audio stream and declaring an interruption listener in order to preserve the state of the song when the interruption occurs - like an incoming call or SMS.

Here is the relevant code

In my AppDelegate I have this

AudioSessionInitialize (NULL, NULL, interruptionListenerCallback, self); AudioSessionSetActive(YES); 

This is what the interrupt listener looks like

 void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) { // This callback, being outside the implementation block, needs a reference //to the AudioPlayer object MyPlayer *player = (MyPlayer *)inUserData; if (interruptionState == kAudioSessionBeginInterruption) { if ([player audioStreamer]) { // if currently playing, pause [player pausePlayback]; player.interruptedOnPlayback = YES; } } else if ((interruptionState == kAudioSessionEndInterruption) && player.interruptedOnPlayback) { // if the interruption was removed, and the app had been playing, resume playback [player resumePlayback]; player.interruptedOnPlayback = NO; } 

}

When I receive a phone call, the interrupt listener is called, and if the user rejects the call, the resume resume method is also called. But before calling the resumePlayback method, I get this error in the console for AudioQueueEnqueueBuffer

error: tca! int error: 560030580

Does anyone have an idea on how to properly handle audio interruptions when streaming audio files.

Thanks.

+6
iphone audio streaming
source share
3 answers

This link shows what the problem is. May help someone.

https://devforums.apple.com/message/31758#31758

+3
source share

! act - kAudioSessionNotActiveError declared in AudioServices.h with comment

"The operation failed because AudioSession is not active. Calling AudioSessionSetActive (true) first will fix this error in most cases."

You also get this error when you call AudioQueueStart () after an interrupt (as I found out today).

+2
source share

It seems to me that you are setting inUserData as your appDelegate instead of your player.

0
source share

All Articles