views:

77

answers:

0

I'd like to pause my app when the user pauses music on his headphones.

[[NSNotificationCenter defaultCenter] addObserver:self 
  selector:@selector(playbackStateDidChange:) 
  name:MPMusicPlayerControllerPlaybackStateDidChangeNotification 
  object:[MPMusicPlayerController iPodMusicPlayer]];

works well. However, this is also triggered on an incoming phone call.

I added

[[NSNotificationCenter defaultCenter] addObserver:self 
  selector:@selector(appLostFocus:) 
  name:UIApplicationWillResignActiveNotification 
  object:[UIApplication sharedApplication]];

Unfortunately, this is triggered after the pause is detected.

Any ideas?