Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerPlaybackDidFinishNotification gets called when it shouldn't

According to Apple's MPMoviePlayerController doc:

MPMoviePlayerPlaybackDidFinishNotification - This notification is not sent in cases where the movie player is displaying in fullscreen mode and the user taps the Done button.

Seems to me this is dead wrong. Using the code below, playerPlaybackDidFinish gets called when I tap the done button.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];

- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
    NSLog(@"WHY?");
    self.player.fullscreen = NO;
}

I need to distinguish between the user tapping the done button and the movie finishing all the way through playback. playerPlaybackDidFinish does get called when the movie ends, but like I said it also gets called when you tap Done.

like image 882
sol Avatar asked Nov 11 '10 19:11

sol


2 Answers

Here is how you check the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey which is part of the notification of MPMoviePlayerPlaybackDidFinishNotification

- (void) playbackDidFinish:(NSNotification*)notification {
    int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
    if (reason == MPMovieFinishReasonPlaybackEnded) {
        //movie finished playin
    }else if (reason == MPMovieFinishReasonUserExited) {
        //user hit the done button
    }else if (reason == MPMovieFinishReasonPlaybackError) {
        //error
    }
}
like image 176
GhostM Avatar answered Oct 29 '22 03:10

GhostM


I am using the following to do something when a movie is played all the way to the end:

- (void)playbackDidFinish:(NSNotification*)notification
{
    BOOL playbackEnded = ([[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue] == MPMovieFinishReasonPlaybackEnded);
    BOOL endReached = (self.player.currentPlaybackTime == self.player.playableDuration);

    if (playbackEnded && endReached) {
        // Movie Ended
    }
}
like image 32
tagy22 Avatar answered Oct 29 '22 05:10

tagy22