使用MPMediaPlaylist填充MPMusicPlayerController时,如何前进到下一个项目,并在那里开始播放?

时间:2011-05-24 18:02:07

标签: ios mpmusicplayercontroller

这就是我正在做的事情:

self.iPodController = [MPMusicPlayerController applicationMusicPlayer];
MPMediaPlaylist* playlist = [self lookupSavedPlaylist];
[self.iPodController setQueueWithItemCollection:playlist];

[self.iPodController skipToNextItem];
[self.iPodController play];

这导致第一首歌曲播放,而不是第二首歌曲。这种是有道理的,但它很烦人,我希望有一个解决办法。

1 个答案:

答案 0 :(得分:3)

嗯,事实证明,如果您明确设置nowPlayingItem,则不会出现此问题。这是修改后的代码:

self.iPodController = [MPMusicPlayerController applicationMusicPlayer];
MPMediaPlaylist* playlist = [self lookupSavedPlaylist];
[self.iPodController setQueueWithItemCollection:playlist];
self.iPodController.nowPlayingItem = [playlist.items objectAtIndex:0]; // explicitly set to track 1 to start

[self.iPodController skipToNextItem]; // will now skip to track 2!
[self.iPodController play]; // will now play track 2