Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Play videos sequentially using MPMoviePlayerController

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 420
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: