2

I am using AVPlayer to play sound from different sources (including iPod music library). Due to the fact that AVPlayer is more low level AVAudioPlayer I have to handle interruptions myself. Using AVAudioPlayer is not an option!

In the Apple developer documents they mention to either listen AVAudioSessionInterruptionNotificationor setup a listener with AudioSessionInitialize. But when doing so I only receive notifications when the interruption ended, but due to their documents my app should be able to handle both.

I am using the following code to initialize my audio session: (simplified version, removed unimportant lines)

AudioSessionInitialize(NULL, NULL, ARInterruptionListenerCallback, nil);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(true);

And here is how the listener looks like:

void ARInterruptionListenerCallback(void *inUserData, UInt32 interruptionState) {
    if (interruptionState == kAudioSessionBeginInterruption) {
        // Here is the code which is never called...
    }
    else if (interruptionState == kAudioSessionEndInterruption) {
        // But this case will be executed!
    }
}

Btw. I am expecting this code executed when there is an interruption like a phone call or similar. Am I misunderstand what Apple declares as interruption?

miho
  • 11,765
  • 7
  • 42
  • 85
  • Hey,@miho i also have same issue . when i getting call & siri interruption is working fine began & end both . but when i am opening iPod music library & play some music file then interruption began is called but interruption end is never called why . please any one have a solution for that. please post on SO i will definitely give a upWot . – Hiren kanetiya Jun 15 '18 at 12:30

1 Answers1

5

There is a bug in iOS 6. The interrupt code never seems to be called for begin interrupt - That includes both the old deprecated method (using AVAudioSession delegate) and the new notification method.

Myself and a few others have raised a high severity bug request with Apple so I suggest you do the same (bugreport.apple.com) to get their attention.

I'm not sure what you're using the interrupt for, but I was using it to allow audio to resume after the interrupt if necessary, and also update the play/pause button in the interface. I had to change my method to watch the AVPlayer rate property to toggle the play/pause button, and not allow audio to resume after an interruption.

Edit: see this thread

Community
  • 1
  • 1
sam_899
  • 306
  • 2
  • 7
  • Thanks for your response. I also created a work around like that. I am going to report this issue to now. – miho Oct 14 '12 at 12:37