How to determine the remote pause (in headphones) compared to an incoming call

I want to pause my application when the user stops the music on the headphones.

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

works good. However, this also works with an incoming phone call.

I added

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

Unfortunately, this is triggered after a pause is detected.

Any ideas?

+3
source share
1 answer

There is no documented way to do this. It may be possible with private APIs, but you know the song.

0
source

Source: https://habr.com/ru/post/1747249/


All Articles