Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Done button event MPMoviePlayerController

On my iPhone i'm playing video/audio files in fullscreen mode. When the video/audio file reached its end then the following method is triggered:

- (void) movieFinishedCallback:(NSNotification*) aNotification {     MPMoviePlayerController *player = [aNotification object];      [player stop];      [[NSNotificationCenter defaultCenter]          removeObserver:self         name:MPMoviePlayerPlaybackDidFinishNotification         object:player];      [player autorelease];     [moviePlayer.view removeFromSuperview];      NSLog(@"stopped?"); } 

That works fine! But the problem is when i press on the "Done" button when the video/audio file is still playing. Then this method doesn't get triggered...

Anyone any idea how to catch the event when the "Done" button is pressed? Because right now media player stays in the view. Its not disappearing.

like image 343
w00 Avatar asked Nov 22 '11 13:11

w00


2 Answers

It worked for me on iPad when I listen to MPMoviePlayerWillExitFullscreenNotification.

[[NSNotificationCenter defaultCenter] addObserver:self                                           selector:@selector(doneButtonClick:)                                               name:MPMoviePlayerWillExitFullscreenNotification                                             object:nil]; 

And selector method:

-(void)doneButtonClick:(NSNotification*)aNotification{     NSNumber *reason = [notification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];      if ([reason intValue] == MPMovieFinishReasonUserExited) {         // Your done button action here     } } 
like image 164
beryllium Avatar answered Oct 04 '22 11:10

beryllium


check for a enum inside notification userInfo dictionary

NSNumber *reason = [notification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];  if ([reason intValue] == MPMovieFinishReasonUserExited) {     // done button clicked!  } 

Selected answer has since integrated my response. Please refer above.

like image 28
dklt Avatar answered Oct 04 '22 11:10

dklt