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

发布于 2024-11-09 18:43:42 字数 362 浏览 0 评论 0原文

这就是我正在做的:

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

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

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

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, not the second. This kind of makes sense, but it's annoying and I'm hoping there's a work-around.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸短情长 2024-11-16 18:43:42

事实证明,如果您显式设置 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文