gpt4 book ai didi

ios - 在 Swift 的 MPMediaItemCollection 的特定索引处播放歌曲

转载 作者:搜寻专家 更新时间:2023-10-31 08:33:50 25 4
gpt4 key购买 nike

我尝试用 Swift 制作我自己的音乐播放器。我需要跳转到我的 MPMediaItemCollection 的特定歌曲/索引并开始播放它,但我只能找到像 skipToNextItem() 和 skipToPreviousItem() 这样的方法。除了循环之外,还有其他方法可以做到这一点吗?

let player = MPMusicPlayerController.systemMusicPlayer()
player.setQueueWithItemCollection(mediaCollection)
player.play()

最佳答案

根据 the documentation ,我们使用 nowPlayingItem 属性。

To specify that playback should begin at a particular media item in the playback queue, set this property to that item while the music player is stopped or paused.

因此,听起来您应该停止或暂停播放器,设置 nowPlayingItem,然后再次调用 play

player.nowPlayingItem = mediaCollection.items[selectedIndex]
player.play()

关于ios - 在 Swift 的 MPMediaItemCollection 的特定索引处播放歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31292774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com