0

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. Only secondVideoItem not 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

ios developer
  • 3,363
  • 3
  • 51
  • 111

1 Answers1

2

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];
 }
}
BhushanVU
  • 3,455
  • 1
  • 24
  • 33
  • Thanks for the quick reply.. I play the both the video.I want to play only the second video to 10-15time.I dont want to start it all again.I just want to start the 2nd video .IS it possible.if yes then please guide me – ios developer Mar 12 '13 at 10:30
  • yes by above code it should rewind or replay ur secondItem.n it should start playing again..try if its doing it... – BhushanVU Mar 12 '13 at 10:31
  • I had tried it..But it play both :- video1 and video2 files.I want to play only video2 in loop – ios developer Mar 12 '13 at 10:34
  • @shweta after watching this it doesn't seem 'not working code' answer you posted http://stackoverflow.com/questions/14765990/avqueueplayer-loop-last-item-in-a-queue-and-eliminate-hiccup-or-loop-last-sec – BhushanVU Mar 12 '13 at 10:47
  • is there any way that instead of taking new layer.We can repeat only the 2nd item of array to play loop.As it gives the minor jerk by doing in this way.. – ios developer Mar 12 '13 at 11:37
  • when 1video file end and then 2nd start the is delay of some milisecond,which show the jerk. – ios developer Mar 13 '13 at 07:08
  • 1
    may be because you are starting it from very beginning 0th sec frame so what you can try is [queuePlayer seekToTime:CMTimeMakeWithSeconds(1,1)]; another thing if i am right,you are adding layer again while making new queue, you can reuse old layer without addSubLayer-ing it again... – BhushanVU Mar 13 '13 at 07:16