2

I need to handle AVPlayer interruptions like incoming calls and headphones unplugging.

So i'm trying to use the following code:

ViewController.h

@interface ViewController : UIViewController <UIWebViewDelegate, AVAudioSessionDelegate>

ViewController.m

- (void)viewDidLoad
{
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive:YES error:nil];
    [[AVAudioSession sharedInstance] setDelegate:self];
}

- (void)beginInterruption
{

}

- (void)endInterruption
{

}

- (void)endInterruptionWithFlags:(NSUInteger)flags
{

}

beginInterruption and endInterruptionWithFlags: were called when the incoming call was received, but not when headphones were unplugged.

I can use callback instead of delegate but i don't want to duplicate the code.

FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
  • Here is a good discussion on detecting if headphones are plugged in. http://stackoverflow.com/questions/3575463/detecting-if-headphones-are-plugged-into-iphone – Mark McCorkle May 08 '13 at 15:21

0 Answers0