【发布时间】:2015-05-01 20:08:26
【问题描述】:
我正在处理应用程序的上一个/队列视图,但是当用户重新排序队列时,播放器要么什么都不做,继续播放正常顺序或添加代码,它有一个非常小的停顿在它更新队列之前。该问题类似于Brief stop/start of Now Playing item when updating a media collection queue MPMediaItemCollection,但没有有效的答案。这是我的代码:
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
var itemToMove = self.queueCopy[fromIndexPath.row + self.currentIndex] as MPMediaItem
self.queueCopy.removeObjectAtIndex(fromIndexPath.row + self.currentIndex)
self.queueCopy.insertObject(itemToMove, atIndex: toIndexPath.row + self.currentIndex)
let newQueue = MPMediaItemCollection(items: self.queueCopy)
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
appDelegate.currentQueue = newQueue
MPMusicPlayerController.iPodMusicPlayer().setQueueWithItemCollection(newQueue)
var currentTime = MPMusicPlayerController.iPodMusicPlayer().currentPlaybackTime
var currentIndex = MPMusicPlayerController.iPodMusicPlayer().indexOfNowPlayingItem
MPMusicPlayerController.iPodMusicPlayer().nowPlayingItem = newQueue.items[currentIndex] as MPMediaItem
MPMusicPlayerController.iPodMusicPlayer().currentPlaybackTime = currentTime
MPMusicPlayerController.iPodMusicPlayer().play()
}
此方法在使用更新的队列之前暂停轨道。有什么方法可以在不暂停的情况下做到这一点?
谢谢!
【问题讨论】:
-
您可以检查曲目是否播放,然后更新播放。
-
@cmashinho 我将如何更新它?无论玩家是否在玩,我都设置了上面的队列,所以它应该可以正常工作吗?