Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get interruption start/end events for AVPlayer

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.

like image 327
Tinku George Avatar asked Mar 19 '13 15:03

Tinku George


1 Answers

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.

like image 144
Ryan Poolos Avatar answered Nov 05 '22 07:11

Ryan Poolos