最后重播AVQueuePlayer中的项目 [英] Replay items in AVQueuePlayer after last

查看:126
本文介绍了最后重播AVQueuePlayer中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 AVQueuePlayer 中创建类似无限循环的东西。特别是,我想在最后一个组件完成播放后重播整个 NSArray AVPlayerItem

I need to create something like an infinite loop in my AVQueuePlayer. Especially, I want to replay the whole NSArray of AVPlayerItems once the last component finishes playing.

我必须承认,我实际上并不知道如何实现这一目标,并希望你能给我一些线索。

I must admit that I actually do not have any idea how to achieve this and hope you can give me some clues.

推荐答案

在AVQueuePlayer中循环播放一系列视频的最佳方法。

best way to loop a sequence of videos in AVQueuePlayer.

观察AVQueuePlayer中的每个播放项目。

observe for each playeritem in AVQueuePlayer.

queuePlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
for(AVPlayerItem *item in items) {
    [[NSNotificationCenter defaultCenter] addObserver:self 
            selector:@selector(nextVideo:) 
            name:AVPlayerItemDidPlayToEndTimeNotification 
            object:item ];
}

再次插入currentItem以将其排队以进行回放。确保为每个项目寻求零。在advanceToNextItem之后,AVQueuePlayer将从队列中删除currentItem。

on each nextVideo insert the currentItem again to queue it for playback. make sure to seek to zero for each item. after advanceToNextItem the AVQueuePlayer will remove the currentItem from queue.

-(void) nextVideo:(NSNotification*)notif {
    AVPlayerItem *currItem = notif.userInfo[@"object"];
    [currItem seekToTime:kCMTimeZero];
    [queuePlayer advanceToNextItem];
    [queuePlayer insertItem:currItem afterItem:nil];
}

这篇关于最后重播AVQueuePlayer中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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