开发者

When populating a MPMusicPlayerController with an MPMediaPlaylist, how to advance to next item, and begin playback there?

Here's what I'm doing:

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

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

This results in the first song playing, 开发者_如何学Pythonnot the second. This kind of makes sense, but it's annoying and I'm hoping there's a work-around.


Well, it turns out that if you explicitly set the nowPlayingItem, you won't have this issue. Here's the modified code:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜