为什么MPMusicPlayerController调用它现在播放的项目改变选择器方法两次?

时间:2011-08-11 09:13:37

标签: iphone objective-c cocoa-touch media-player mpmusicplayercontroller

  

我正在为iPhone编写音乐播放列表编辑应用程序。

     

我正在订阅MPMusicPlayerController   MPMusicPlayerControllerNowPlayingItemDidChangeNotification而我是   在此通知的@selector方法中遇到问题   在nowPlayingItem:更改时,系统会多次调用。

我已将每个播放列表划分为自己的MPMediaItemCollection对象,当一个播放列表完成后,我会通过调用播放器上的-pause加载下一个播放列表,然后传递新的MPMediaItemCollection通过其-setQueueWithItemCollection:方法到音乐播放器控制器。然后我明确地将nowPlayingItem设置为我自己的item项,最后我调用-play

        [musicPlayer pause];
        [musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:[selectedPrefs mediaItems]]];
        musicPlayer.nowPlayingItem = [selectedPrefs.playbackItems objectAtIndex:selectedPrefs.nowPlayingIndex];
        [musicPlayer play];

当我这样做时,@selector被调用两次,以便正在播放的项目发生变化。我怀疑这是因为-setQueueWithItemCollection:会自动将正在播放的项目更改为指向新集合中的第一个媒体项目,然后我再次更改此项目,然后再调用-play

非常感谢。

0 个答案:

没有答案