I have an iOS7 application with music player. I'm using the following code to check playback state changes from the MPMusicPlayerController to update the UI. More precisely I toggle the look of the play button between play and pause.
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector (handle_NowPlayingItemChanged:)
name: MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object: self.musicPlayer];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector (handle_PlaybackStateChanged:)
name: MPMusicPlayerControllerPlaybackStateDidChangeNotification
object: self.musicPlayer];
[self.musicPlayer beginGeneratingPlaybackNotifications];
if I run the app on iOS7 on an iPad or iPhone, I get the following sequence instead of just one single callback:
-[MyMediaPlayer handle_PlaybackStateChanged:] :: playbackState: 1
-[MyMediaPlayer handle_PlaybackStateChanged:] :: playbackState: 2
-[MyMediaPlayer handle_PlaybackStateChanged:] :: playbackState: 1
-[MyMediaPlayer handle_PlaybackStateChanged:] :: playbackState: 2
playbackState 2 means MPMusicPlaybackStatePaused and causes my application to display the wrong state in the UI, while the song is actually being played back. It doesn't make sense that the callback gets called 4 times, with alternating values.
This happens when changing the queue only. It looks like the system is not clearing the queue properly.
Any ideas on how to solve this ?