How to stop MPMoviePlayerViewController from starting automatically on moviePlaybackDidFinish?

MPMoviePlayerViewController, which is presented modally through presentMoviePlayerViewControllerAnimated: is automatically rejected when it finishes playing.

I tried to disable this, because after that I want to play other content. However, even if I register with NSNotificationCenter using [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer]; and installed other content, it is still rejected.

How can I stop MPMoviePlayerViewController from automatically rejecting itself?

UPDATE:

By way of explanation, this question only concerns the removal of automatic dismissal, and not the handling of the disabled "done" button. The selected answer reflects. This is by design, since we assume that the developer is adding his own rejection facilities to the MPMoviePlayerViewController. However, @bickster also responds with a "done" button.

+7
source share
4 answers

Thanks to this blog article, I found out that MPMoviePlayerViewController automatically registers with NSNotificationCenter upon creation. You must first delete this registration and it will stop automatically shutting down.

 // Initialize the movie player view controller with a video URL string MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease]; // Remove the movie player view controller from the "playback did finish" notification observers [[NSNotificationCenter defaultCenter] removeObserver:playerVC name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer]; 
+20
source

You can use this code to stop the view manager from automatically rejecting and capturing an event when the user clicks the Finish button so that you can close the view manager yourself.

Step 1.- specify MPMoviePlayerViewController

 videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[[NSURL alloc ]initWithString:[aURL]; 

Step 2. - Remove the default MPMoviePlayerPlaybackDidFinishNotification observer and add your own

 [[NSNotificationCenter defaultCenter] removeObserver:videoPlayer name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer]; 

Step 3. - Current view control

 [self presentMoviePlayerViewControllerAnimated:videoPlayer]; 

Step 4. - Add videoFinish: method

 -(void)videoFinished:(NSNotification*)aNotification{ int value = [[aNotification.userInfo valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue]; if (value == MPMovieFinishReasonUserExited) { [self dismissMoviePlayerViewControllerAnimated]; } } 
+20
source

You can try something like this.

when mpmovieplayercontroller finishes playing the video and you get a notification in your movieFinishedCallback: implemect method

  [playerVC.movieplayer setContentURL:// set the url of the file you want to play here]; [playerVC.moviePlayer play]; 

Hope this helps

+2
source

Since the Finish button no longer works, if I MPMoviePlayerPlaybackDidFinishNotification from NSNotificationCenter , I change the repeat mode to MPMovieRepeatModeOne . Then everything that works great except the video is repeated.

 MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease]; [playerVC.moviePlayer setRepeatMode:MPMovieRepeatModeOne]; 
0
source

All Articles