I have a sound manager class that implements the AVAudioSessionDelegate protocol, i.e. the beginInterruption and endInterruption methods.
However, when I ring the phone and go back to the app, neither method gets called and the app is thereafter silent. This is tested using both the debugger and using NSLog calls.
The sound manager class uses openAL.
-
My class is declared like so:
@interface CMOpenALSoundManager : NSObject <AVAudioPlayerDelegate, AVAudioSessionDelegate>
and the delegate implementations are as follows:
- (void)beginInterruption {
[self setActivated:NO];
}
- (void)audioPlayerBeginInterruption {
[self setActivated:NO];
}
- (void)endInterruption {
[self setActivated:YES];
}
- (void)audioPlayerEndInterruption {
[self setActivated:YES];
}
where setActivated:(BOOL)state contains the code to start and stop the sound manager.
-
I can't see any reason for the delegate methods not to be called - perhaps is there something I am forgetting to do when I start up the sound manager or set the audio properties etc?
Or am I blatantly missing something more obvious :o
Any ideas are much appreciated!
This seems to be a bug in iOS. There are various conditions in which the endInterruption
callback is not called. What I've done is to check whether another app is currently playing audio in my applicationWillEnterForeground
method (or to be precise: I've registered to the corresponding notification so I don't have to do it in the app delegate). You can check that via AudioSessionGetProperty and kAudioSessionProperty_OtherAudioIsPlaying.