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 ?
I've been experiencing the same problem since the release of iOS 7. It's defeinitely a problem with iOS; not only is it reporting an incorrect playback state but also on occasions fails to receive playback state change notifications (MPMusicPlayerControllerPlaybackStateDidChangeNotification
)
I've reported the bug to Apple and I suggest you do the same thing (Apple Bug Reporter)
I had the same problem. I found this workaround, instead of use playbackState to check if the audio is playing, I used this condition:
if([[AVAudioSession sharedInstance] isOtherAudioPlaying])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With