在Swift的MPMediaItemCollection的特定索引处播放歌曲
我尝试用Swift制作我自己的Musicplayer。 我需要跳转到我的MPMediaItemCollection特定的歌曲/索引,并开始播放,但我只能find像skipToNextItem()和skipToPreviousItem()方法。 有没有其他的方式来做到这一点比循环?
let player = MPMusicPlayerController.systemMusicPlayer() player.setQueueWithItemCollection(mediaCollection) player.play()
根据文档 ,我们使用nowPlayingItem
属性。
要指定播放应从播放队列中的特定媒体项目开始,请在音乐播放器停止或暂停时将此属性设置为该项目。
所以,这听起来像你应该停止或暂停播放器,设置nowPlayingItem
,然后再次调用play
。
player.nowPlayingItem = mediaCollection.items[selectedIndex] player.play()