4

I had an app which worked correctly in iOS 4.3, after upgrading to iOS 5 it behaves in another way.
After executing these lines on iOS 4.3 mp.playbackState is set to MPMusicPlaybackStatePaused, however in iOS 5 it is still set to MPMusicPlaybackStatePlaying.

MPMusicPlayerController *mp = [MPMusicPlayerController applicationMusicPlayer];
if(mp.playbackState == MPMusicPlaybackStatePlaying)
    [mp pause];

I assume that playbackState is not updated within the same event loop, is it ok?

OtoLeo
  • 363
  • 3
  • 19
  • I had to make a similar workaround described [here][1] [1]: http://stackoverflow.com/questions/10118726/getting-wrong-playback-state-in-mp-music-player-controller-in-ios-5 – matbur Apr 13 '12 at 05:58

1 Answers1

3

I think the issue is:

MPMusicPlaybackState playbackState = [musicPlayer playbackState];

in iOS5 is not always correct.

This work for me:

if (!isPlay) 
{    
   isPlay = TRUE;
   [appPlayer play];
}
else 
{
   isPlay = FALSE;
   [appPlayer pause];
}
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
  • I had to do something like this because I couldn't figure out another solution. – OtoLeo Jan 17 '12 at 15:27
  • I have the same issue, is this a bug? Do you guys see NULL as the .playbackState sometimes? – SimplyKiwi Jan 29 '12 at 05:19
  • No, I never saw NULL. Eventually I used the **MPMusicPlayerControllerPlaybackStateDidChangeNotification** because there I got the correct playbackState. – OtoLeo Jan 30 '12 at 14:57
  • These bugs in iOS SDK are such timer-wasters, our lives are consumed by Apple's carelessness and unwillingness to fix their own mistakes. – Ascendant Oct 19 '14 at 06:08