问题描述
我需要在 AVQueuePlayer
中创建类似无限循环的东西。特别是,我想在最后一个组件完成播放后重播整个 NSArray
的 AVPlayerItem
。
I need to create something like an infinite loop in my AVQueuePlayer
. Especially, I want to replay the whole NSArray
of AVPlayerItem
s 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中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!