2013-03-12 91 views
0

我曾經使用這個視頻播放沒有混蛋。但如何播放secondVideoItem在循環..這是視頻播放後,我想添加此視頻到10-15時間。 只有secondVideoItem不是firstVideoItem在循環播放視頻+ AVQueuePlayer

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

感謝adavnce

回答

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

感謝您的快速回復..我播放這兩個視頻。我只想播放第二個視頻到10-15時間。我不想再次開始播放。我只是想開始第二個視頻.IS它可能。如果是的話請引導我 – 2013-03-12 10:30:30

+0

是的通過上面的代碼它應該倒帶或重放你的secondItem.n它應該開始再次播放..嘗試,如果它做到這一點... – BhushanVU 2013-03-12 10:31:29

+0

我曾試過它..但它播放兩個: - video1和video2 files.I只想播放video2在循環 – 2013-03-12 10:34:18