本文介绍了在Swift中以MPMediaItemCollection的特定索引播放歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试用Swift制作自己的Musicplayer.我需要跳到我的MPMediaItemCollection的特定歌曲/索引并开始播放它,但是我只能找到诸如skipToNextItem()和skipToPreviousItem()之类的方法.除了循环,还有其他方法吗?
I try to make my own Musicplayer with Swift. I need to jump to a specific song/index of my MPMediaItemCollection and start to play it but i can only find methods like skipToNextItem() and skipToPreviousItem(). Is there any other way to do that than with a loop?
let player = MPMusicPlayerController.systemMusicPlayer()
player.setQueueWithItemCollection(mediaCollection)
player.play()
推荐答案
根据文档,我们使用nowPlayingItem
属性.
因此,听起来您应该停止或暂停播放器,设置nowPlayingItem
,然后再次调用play
.
So, it sounds like you should stop or pause the player, set the nowPlayingItem
, and then call play
again.
player.nowPlayingItem = mediaCollection.items[selectedIndex]
player.play()
这篇关于在Swift中以MPMediaItemCollection的特定索引播放歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!