跳到AVQueuePlayer上的上一个AVPlayerItem/从队列中播放选定的项目 [英] Skip to Previous AVPlayerItem on AVQueuePlayer / Play selected Item from queue

查看:159
本文介绍了跳到AVQueuePlayer上的上一个AVPlayerItem/从队列中播放选定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在播放一个电视节目,该节目已使用AVQueuePlayer分割为我项目的不同章节. 我还想提供一种在AVQueuePlayer已经播放的情况下跳到上一章或下一章或动态选择另一章的可能性.

I am playing a Tv-show that has been sliced to different chapters on my project using an AVQueuePlayer. I also want to offer the possibility to skip to the previous/next chapter or to select a different chapter on the fly, while the AVQueuePlayer is already playing.

跳到下一个项目与AVQueuePlayer提供的advanceToNextItem没问题,但是从队列中跳回或播放确定项没有什么不同.

Skipping to next Item is no problem with the advanceToNextItem provided by AVQueuePlayer, but there is nothing alike for skipping back or playing a certainitem from the queue.

所以我不太确定这里最好的方法是什么

So I am not quite sure what would be the best approach here:

  1. 使用AVPlayer代替AVQueuePlayer,在actionAtItemEnd处调用replaceCurrentItemWithPlayerItem:来播放nextItem,而仅使用'replaceCurrentItemWithPlayerItem'来让用户选择某个章节
  1. Using an AVPlayer instead of AVQueuePlayer, invoke replaceCurrentItemWithPlayerItem: at actionAtItemEnd to play the nextItem and just use 'replaceCurrentItemWithPlayerItem' to let the User select a certain Chapter

  1. 使用"insertItem:afterItem:"和"removeAllItems"重新组织队列或当前播放器

其他信息: 我按照在NSArray中出现的顺序存储指向不同视频的路径 用户应该通过按代表该章节的按钮来跳到某些章节.按钮具有标签,它们也是数组中相应视频的索引.

Additional information: I store the Path to the different videos in the order they should appear in a NSArray The user is supposed to jump to certain chapters by pressing buttons that represent the chapter. The Buttons have tags, that are also the indexes of the corresponding videos in the array.

希望我能说清楚吗? 任何人有这种情况的经验吗? 如果有人知道在哪里可以买到具有功能的IOS VideoPlayerFramework,我也非常感谢您的链接.

Hope I could make myself clear? Anyone having any experience with this situation? If anyone knows where to buy a good IOS VideoPlayerFramework which provides the functionality, I would also appreciate the link.

推荐答案

如果您希望程序可以播放上一个项目并播放playeritems(NSArray)中的选定项目,则可以执行此操作.

If you want your program can play previous item and play the selected item from your playeritems(NSArray),you can do this.

- (void)playAtIndex:(NSInteger)index
{
    [player removeAllItems];
    for (int i = index; i <playerItems.count; i ++) {
        AVPlayerItem* obj = [playerItems objectAtIndex:i];
        if ([player canInsertItem:obj afterItem:nil]) {
        [obj seekToTime:kCMTimeZero];
        [player insertItem:obj afterItem:nil];
        }
    }
}

playerItems是存储AVPlayerItems的NSMutableArray(NSArray).

edit: playerItems is the NSMutableArray(NSArray) where you store your AVPlayerItems.

这篇关于跳到AVQueuePlayer上的上一个AVPlayerItem/从队列中播放选定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆