2012-01-13 35 views
4

我有一个应用程序,在iOS 4.3中正常工作,升级到iOS 5后,它的行为以另一种方式。
在iOS 4.3上执行这些行后,mp.playbackState被设置为MPMusicPlaybackStatePaused,但是在iOS 5中它仍然被设置为MPMusicPlaybackStatePlaying。MPMusicPlayerController是否随iOS 5更改?

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

我假设playbackState没有在同一事件循环内更新,可以吗?

+0

我不得不做出描述这里]类似的解决方法[1] [1]:http://stackoverflow.com/questions/10118726 /越来越错误播放状态在mp音乐播放器控制器在ios-5 – matbur 2012-04-13 05:58:42

回答

3

我认为这个问题是:

MPMusicPlaybackState playbackState = [musicPlayer playbackState]; 

在iOS5中并不总是正确的。

这项工作对我来说:

if (!isPlay) 
{  
    isPlay = TRUE; 
    [appPlayer play]; 
} 
else 
{ 
    isPlay = FALSE; 
    [appPlayer pause]; 
} 
+0

我不得不这样做,因为我无法找出另一种解决方案。 – OtoLeo 2012-01-17 15:27:36

+0

我有同样的问题,这是一个错误?你们有时看到.playbackState为NULL吗? – 2012-01-29 05:19:58

+0

不,我从来没有见过NULL。最终我使用了** MPMusicPlayerControllerPlaybackStateDidChangeNotification **,因为我得到了正确的playbackState。 – OtoLeo 2012-01-30 14:57:44