I am playing audio files with AVPlayer
.
I implemented AVAudioSessionInterruptionNotification
.
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *errorInAudio = nil;
[session setActive:YES error:&errorInAudio];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
It works fine when an interruption came while the app is in foreground(like voice control).
But I made the app in background mode and opened the iPod player and start playing. Its interruption is not getting called at that time and even when my app entered foreground.
What may be the problem. Please help.
If you use AVAudioPlayer
you can conform to AVAudioPlayerDelegate
then you can implement methods like - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
More methods listed in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With