ios - AVQueuePlayer: Loop last item in a queue (and eliminate hiccup) or loop last seconds of a video -
i using avqueueplayer play videos in sequence (although have hiccups between plays). i'd to:
1) loop lastly item in sequence (not total one).
2) in doing so, i'd eliminate hiccups.
below code play videos sequence. how accomplish 2 goals?
[super viewdidload]; nsstring *secondvideopath = [[nsbundle mainbundle] pathforresource:@"vid_1" oftype:@"mov"]; nsstring *firstvideopath = [[nsbundle mainbundle] pathforresource:@"vid_2" oftype:@"mov"]; avplayeritem *firstvideoitem = [avplayeritem playeritemwithurl:[nsurl fileurlwithpath:firstvideopath]]; avplayeritem *secondvideoitem = [avplayeritem playeritemwithurl:[nsurl fileurlwithpath:secondvideopath]]; queueplayer = [avqueueplayer queueplayerwithitems:[nsarray arraywithobjects:firstvideoitem, secondvideoitem,nil]]; avplayerlayer *layer = [avplayerlayer playerlayerwithplayer:queueplayer]; avplayer.actionatitemend = avplayeractionatitemendnone; layer.frame = cgrectmake(0, 0, 1024, 768); [self.view.layer addsublayer:layer]; [queueplayer play];
another method i'm thinking of play 1 long video , loop lastly few seconds of it. perhaps avoid hiccups way. approach achievable? if so, how adapt code below (that plays 1 video)?
[super viewdidload]; nsstring *filepath = [[nsbundle mainbundle] pathforresource:@"vid_long" oftype:@"mov"]; nsurl *fileurl = [nsurl fileurlwithpath:filepath]; avplayer = [avplayer playerwithurl:fileurl]; avplayerlayer *layer = [avplayerlayer playerlayerwithplayer:avplayer]; avplayer.actionatitemend = avplayeractionatitemendnone; layer.frame = cgrectmake(0, 0, 1024, 768); [self.view.layer addsublayer: layer]; [avplayer play];
here solution play video in loop:-
queueplayer.actionatitemend = avplayeractionatitemendnone; int k=0; [[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]; } }
by edited answer:- above reply play same files works me. play lastly added file in loop:
- (void)itemplayended1:(nsnotification *)notification { nsstring *secondvideopath = [[nsbundle mainbundle] pathforresource:@"video2" oftype:@"mp4"]; k=0; avplayeritem *secondvideoitem = [avplayeritem playeritemwithurl:[nsurl fileurlwithpath:secondvideopath]]; // avplayeritem *p = [notification object]; nsmutablearray *currentitemarray = [nsmutablearray arraywithobjects:secondvideoitem,nil]; avqueueplayer* queueplayer = [[avqueueplayer alloc] initwithitems:currentitemarray]; [queueplayer play]; queueplayer.actionatitemend = avplayeractionatitemendnone; avplayerlayer *layer = [avplayerlayer playerlayerwithplayer:queueplayer]; avplayer.actionatitemend = avplayeritemstatusreadytoplay; layer.frame = cgrectmake(0, 0, 1024, 768); [self.view.layer addsublayer:layer]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(itemplayended:) name:avplayeritemdidplaytoendtimenotification object:[queueplayer currentitem]]; }
ios video sequence layer avqueueplayer
No comments:
Post a Comment