简体   繁体   English

在循环播放视频+ AVQueuePlayer

[英]Play video in loop +AVQueuePlayer

I had used this video to play without jerk.But how to play the secondVideoItem in loop..That is after video get play i want to add this video to 10-15time. 我曾经使用过这个视频没有混蛋。但是如何在循环中播放secondVideoItem ..这是在视频播放后我想将此视频添加到10-15次。 Only secondVideoItem not firstVideoItem . 只有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];

Thanks in adavnce 谢谢你的意见

After played the second item this will call a notification and rewind the video so it will start playing again... 播放第二个项目后,这将调用通知并回放视频,以便它再次开始播放...

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];
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM