我正在为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
。
非常感谢。