Hello All,
Sometime we want to play all videos of gallery sequentially. These lines of code will help you to play videos sequentially using MPMoviePlayerController.
it worked for me.
In .h file..
MPMoviePlayerController *moviePlayer;
int counter;
In .m file..
-(void)PlayVideos{
counter = 0;
NSString *url = [self.Videos objectAtIndex:0];
NSURL *fileURL = [NSURL URLWithString:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
moviePlayer.controlStyle=MPMovieControlStyleFullscreen;
moviePlayer.shouldAutoplay=YES;
[moviePlayer prepareToPlay];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
counter ++;
NSLog(@"counter = %d",counter);
if (counter < self.Videos.count) {
NSString *url = [self.Videos objectAtIndex:counter];
NSURL *fileURL = [NSURL URLWithString:url];
NSLog(@"file url = %@",fileURL);
[moviePlayer setContentURL:fileURL];
[moviePlayer play];
}else
{
[moviePlayer.view removeFromSuperview];
}
}
Happy coding.
0 Comment(s)