0

我用这个视频播放没有混蛋。但是如何在循环中播放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];

提前感谢

4

1 回答 1

2

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

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];
 }
}
于 2013-03-12T10:24:16.660 回答