0
我在播放本地队列(保存在设备上)歌曲时遇到了麻烦。我正在使用这种椰子树 - https://github.com/tumtumtum/StreamingKit。我的第一个队列中的第一个项目在完成后开始再玩一次。 它stopReason状态无StreamingKit重复播放歌曲ios
func audioPlayer(_ audioPlayer: STKAudioPlayer, didFinishPlayingQueueItemId queueItemId: NSObject, with stopReason: STKAudioPlayerStopReason, andProgress progress: Double, andDuration duration: Double) {
if stopReason == .eof || stopReason == .pendingNext {
checkNextTrack()
}
if stopReason == .none {
print("NONE")
}
if stopReason == .error || stopReason == .userAction || stopReason == .disposed {
stop()
resetAudioPlayer()
}
}
其他要素有状态.eof
或.pendingNext
这是正确的行为。我应该怎么做呢?所有远程网址都正确播放。 Thnx!
UPDATE: 队列生成
internal func playWithQueue(queue: [Song], index: Int = 0) {
var audioListNew = [AudioItem]()
for (index, value) in queue.enumerated() {
let audioItem = AudioItem(audioItem: value, audioIndex: index)
audioListNew.append(audioItem)
}
guard index >= 0 && index < audioListNew.count else { return }
newQueue(queue: audioListNew, index: index)
}
func newQueue(queue: [AudioItem], index: Int = 0) {
self.queue = queue
audioPlayer.clearQueue()
if let currentSong = self.queue[index].audioItem {
play(file: currentSong)
for (songIndex, _) in queue.enumerated() {
audioPlayer.queue((queue[Int((index + songIndex) % queue.count)].audioItem?.songRealUrl)!)
}
}
currentIndex = index
}
嘿。你的第一个项目在没有理由完成之后再玩一次,或者因为你在所有剩下的事情之后排队玩它? – tumtumtum
@tumtumtum无理由。我可以给你我的代码的一部分,我创建一个队列。也许我做错了 –
@tumtumtum更新了我的问题 –