我在应用程序中使用了一个 AVQueuePlayer
。我有两个划动手势,可以跳转到下一个和上一个 avplayeritem。现在,为了跳到下一个,我只是调用了 avqueueplayer 上的 advanceToNextItem,这个方法运行得很好。
然而,对于上一个跳过操作,我正在删除所有项目,并将它们再次添加到队列中,以前一个视频在最前面。这在多次跳过上一个视频时非常慢。如何让这个过程变得更快,就像调用advanceToNextItem
一样?
我的代码如下:
func skipToPrevious() {
queuePlayer.removeAllItems()
// move the previous playerItem to the front of the list then add them all back in
for playerItem in playerItems:
queuePlayer.insertItem(playerItem, afterItem: nil)
}