gpt4 book ai didi

iphone - 循环播放视频 +AVQueuePlayer

转载 作者:行者123 更新时间:2023-11-28 22:38:08 31 4
gpt4 key购买 nike

我用这个视频播放时没有卡顿。但是如何循环播放 secondVideoItem..那是在视频播放后我想将这个视频添加到 10-15time。只有 secondVideoItem 而不是 firstVideoItem

NSString *secondVideoPath = [[NSBundle mainBundle] pathForResource:@"video1" ofType:@"mp4"];
NSString *firstVideoPath = [[NSBundle mainBundle] pathForResource:@"video2" ofType:@"mp4"];


AVPlayerItem *firstVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:firstVideoPath]];
AVPlayerItem *secondVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:secondVideoPath]];

AVQueuePlayer* queuePlayer = [AVQueuePlayer queuePlayerWithItems:[NSArray arrayWithObjects:firstVideoItem, secondVideoItem,nil]];

AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:queuePlayer];
avPlayer.actionAtItemEnd = AVPlayerItemStatusReadyToPlay;
layer.frame = CGRectMake(0, 0, 1024, 768);

[self.view.layer addSublayer:layer];

[queuePlayer play];

提前致谢

最佳答案

播放第二个项目后,这将调用通知并倒带视频,以便再次开始播放...

queuePlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(itemPlayEnded:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[queuePlayer currentItem]];

- (void)itemPlayEnded:(NSNotification *)notification
{
k++;
if(k<10-15 times)
{
AVPlayerItem *p = [notification object];
[p seekToTime:kCMTimeZero];
}
}

关于iphone - 循环播放视频 +AVQueuePlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15358274/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com