假设队列已经初始化,我看到的将项目添加到队列的唯一方法是:
- (void)insertItem:(AVPlayerItem *)item afterItem:(AVPlayerItem *)afterItem
文档说传递 nil 将项目追加到队列中。
那么是不是不可能将一个项目添加到队列顶部呢?我希望能够重播之前播放的内容,而无需删除所有内容并将其重新排队。
最佳答案
Larme 的上述评论让我思考,实际上我能够通过执行以下操作来模仿我正在寻找的行为:
// pause the player since we're messing with the currently playing item
[_avQueuePlayer pause];
// get current first item
id firstItem = [_avQueuePlayer.items objectAtIndex:0];
// add new item in 2nd spot
[_avQueuePlayer insertItem:newItem afterItem:firstItem];
// remove our first item so the new item becomes first in line
[_avQueuePlayer removeItem:firstItem];
// now add the original first item back in after the newly insert item
[_avQueuePlayer insertItem:firstItem afterItem:newItem];
// continue playing again
[_avQueuePlayer play];
这太棒了!我认为唯一的缺点是玩家必须再次缓冲我们删除并重新插入的下一个项目。但是队列中的剩余项目将保持缓冲状态,因此这比必须重置整个队列要好。
关于ios - 可以使用 AVQueuePlayer 在队列顶部插入项目吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24502280/