-->

Did MPMusicPlayerController change with iOS 5?

2019-06-24 04:07发布

问题:

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?

回答1:

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];
}