ios - 可以使用 AVQueuePlayer 在队列顶部插入项目吗?

标签 ios avplayer avqueueplayer

假设队列已经初始化,我看到的将项目添加到队列的唯一方法是:

- (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/

相关文章:

ios - 更改 AVPlayerViewController 控件的位置

swift - AVPlayer m3u8 视频结束问题

swift - iOS swift - 录制多个视频片段在 AVQueuePlayer 中播放时卡住

ios - iOS 开发证书到期对分发配置文件有什么影响?

ios - 如何减少 Swift 中的代码冗余?

ios - 嵌入式 AVPlayer 不播放视频

ios - 预加载 AVPlayer 流式视频

objective-c - 当 AVQueuePlayer 完成最后一个播放器项目时如何做某事

javascript - 找不到变量 : Promise on Safari

objective-c - UIScrollView 不显示滚动条(滚动指示器)