我正在使用 AVQueuePlayer 按顺序播放视频(尽管我在播放之间有打嗝)。现在我想:
1)循环该序列中的最后一项(不是完整的)。
2)这样做,我也想消除打嗝。
下面是我播放视频序列的代码。我怎样才能实现我的 2 个目标?
[super viewDidLoad];
NSString *secondVideoPath = [[NSBundle mainBundle] pathForResource:@"vid_1" ofType:@"mov"];
NSString *firstVideoPath = [[NSBundle mainBundle] pathForResource:@"vid_2" ofType:@"mov"];
AVPlayerItem *firstVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:firstVideoPath]];
AVPlayerItem *secondVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:secondVideoPath]];
queuePlayer = [AVQueuePlayer queuePlayerWithItems:[NSArray arrayWithObjects:firstVideoItem, secondVideoItem,nil]];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:queuePlayer];
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
layer.frame = CGRectMake(0, 0, 1024, 768);
[self.view.layer addSublayer:layer];
[queuePlayer play];
我正在考虑的另一种方法是播放 1 长视频并循环播放最后几秒钟。也许我也可以这样避免打嗝。这种方法可以实现吗?如果是这样,如何调整下面的代码(播放 1 个视频)?
[super viewDidLoad];
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"vid_long" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
avPlayer = [AVPlayer playerWithURL:fileURL];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
layer.frame = CGRectMake(0, 0, 1024, 768);
[self.view.layer addSublayer: layer];
[avPlayer play];