Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to play play video on current viewcontroller with full screen. so i am using MPMoviePlayerViewController to play full screen video but problem is that it does not play smooth. it lag little bit while playing video. Here is My code which i am using to play full screen video which is store in my documents directory of phone/ipad

-(void)PlayVideo:(NSString *)videoFilePath
  {
NSURL *videoURL = [NSURL fileURLWithPath:videoFilePath];

NSLog(@"videoURL: %@", videoURL);

MPMoviePlayerViewController *playerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:playerVC
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:playerVC.moviePlayer];

// Register this class as an observer instead
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieFinishedCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:playerVC.moviePlayer];

// Set the modal transition style of your choice
playerVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

// Present the movie player view controller
[self presentViewController:playerVC animated:NO completion:nil];

// Start playback
[playerVC.moviePlayer prepareToPlay];
[playerVC.moviePlayer play];

  }
- (void)movieFinishedCallback:(NSNotification*)aNotification
 {
// Obtain the reason why the movie playback finished
NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

// Dismiss the view controller ONLY when the reason is not "playback ended"
if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded)
{
    MPMoviePlayerController *moviePlayer = [aNotification object];

    // Remove this class from the observers
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayer];

    // Dismiss the view controller
    [self dismissViewControllerAnimated:YES completion:Nil];
   }
   }
share|improve this question

1 Answer

Didn't find any issue with the code except in

[[NSNotificationCenter defaultCenter] removeObserver:playerVC
                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:playerVC.moviePlayer];

removeObserver should be self and not playerVC.

But ya, that will not cause any problem like you have mentioned.

I would suggest you try profiling your app, which might direct you to the code causing the issue. Probably there might be something that you are doing in the background when the video is playing which is causing it to lag.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.