Reject MPMoviePlayerViewController from a playback error

I have a problem with MPMoviePlayerViewController: if the controller cannot find the movie at the specified URL, it displays a white screen and I cannot close it.

This is how I launch the movie player:

- (void) playVideo:(NSString*)path { NSURL* url = [NSURL URLWithString:path]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; double osversion = [[[UIDevice currentDevice] systemVersion] doubleValue]; if (osversion >= 3.2) { mplayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; if (mplayerVC) { mplayerVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile; [mplayerVC.moviePlayer play]; mplayerVC.moviePlayer.shouldAutoplay = TRUE; [self presentMoviePlayerViewControllerAnimated:mplayerVC]; //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; } } } 

and the moviePlayBackDidFinish method looks like this:

 - (void) moviePlayBackDidFinish:(NSNotification*)notification { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; NSError* error = [[notification userInfo] valueForKey:@"error"]; if (error != nil) { // Movie ended with an error DLog(@"error=%@", error); } else { // Movie ended successfully } [self dismissMoviePlayerViewControllerAnimated]; SAFE_DEL(mplayerVC); } 

A white screen appears only if the URL is incorrect

+4
source share
1 answer

Ignore the guys, I figured it out.

Apparently in the moviePlaybackDidFinish method you should call

 [player stop]; 

before rejecting the controller.

Above, the player is an MPMoviePlayerController object obtained as follows:

 MPMoviePlayerController *player = [notification object]; 
+3
source

All Articles