views:

706

answers:

3

Hi

I am developing an audio streamer and have declared an interruption listener to save state of a song when an interruption occurs - like an incoming call or an sms.

Here is the relevant code

In my AppDelegate, I have this

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

This is what the interruption 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 get a phone call the interruption listener is called and if the user declines the call the playback resume method is also called. But before the resumePlayback method is called, I get this error in the console for AudioQueueEnqueueBuffer

error: tca! error int: 560030580

Does anyone have an idea of how to correctly handle audio interruptions when streaming audio files.

Thanks.

+2  A: 

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

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

lostInTransit
A: 

It looks to me like you are setting inUserData as your appDelegate instead of your player.

John Fricker
A: 

!act is kAudioSessionNotActiveError, declared in AUdioServices.h, with the comment

"The operation failed because the 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 interruption (as I found out today).

Frank Shearar