MPMoviePlayerPlaybackDidFinishNotification gets called when it shouldn't

前端 未结 4 425
走了就别回头了
走了就别回头了 2021-02-06 13:19

According to Apple\'s MPMoviePlayerController doc:

MPMoviePlayerPlaybackDidFinishNotification - This notification is not sent in cases where the movie player is displayi

相关标签:
4条回答
  • 2021-02-06 13:56

    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
        }
    }
    
    0 讨论(0)
  • 2021-02-06 14:03

    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
        }
    }
    
    0 讨论(0)
  • 2021-02-06 14:08

    Make sure for

        moviePlayer.repeatMode = MPMovieRepeatModeNone;
    
    0 讨论(0)
  • 2021-02-06 14:09

    When you get the notification you can check the player's endPlaybackTime. If it's -1 then the movie finished all the way back naturally.

    For streamed content, you can check the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey inside the userInfo on the MPMoviePlayerPlaybackDidFinishNotification.

    If it's equal to MPMovieFinishReasonUserExited then it's the user stopped playing the content.

    0 讨论(0)
提交回复
热议问题