【发布时间】:2017-06-03 11:57:32
【问题描述】:
我在播放本地(保存在设备上)歌曲队列时遇到问题。我正在使用这个 cocoapod - https://github.com/tumtumtum/StreamingKit。我在队列中的第一个项目在完成后开始再播放一次。 它的 stopReason 状态为 NONE
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,这是正确的行为。在这种情况下我该怎么办?所有远程 url 都在正确播放。
谢谢!
更新: 队列创建
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 我提到我队列中的每首歌曲都以状态 .none 结尾,但播放器切换到下一首歌曲。这是正常行为吗?
标签: ios objective-c swift cocoapods audio-player