不应该调用MPMoviePlayerPlaybackDidFinishNotification

时间:2022-04-19 02:11:16

According to Apple's MPMoviePlayerController doc:

根据Apple的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.

MPMoviePlayerPlaybackDidFinishNotification - 如果电影播放器​​以全屏模式显示并且用户点击完成按钮,则不会发送此通知。

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

在我看来这是错误的。使用下面的代码,当我点击完成按钮时,会调用pl​​ayerPlaybackDidFinish。

[[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.

我需要区分用户点击完成按钮和电影完成播放完成。当电影结束时,playerPlaybackDidFinish会被调用,但就像我说的那样,当你点击Done时它也会被调用。

4 个解决方案

#1


22  

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

以下是检查MPMoviePlayerPlaybackDidFinishReasonUserInfoKey的方法,这是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
    }
}

#2


3  

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
    }
}

#3


2  

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.

收到通知后,您可以查看播放器的endPlaybackTime。如果它是-1那么电影自然地完成了。

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

对于流内容,您可以检查MPMoviePlayerPlaybackDidFinishNotification上userInfo内的MPMoviePlayerPlaybackDidFinishReasonUserInfoKey。

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

如果它等于MPMovieFinishReasonUserExited那么它就是用户停止播放内容。

#4


0  

Make sure for

确保

    moviePlayer.repeatMode = MPMovieRepeatModeNone;

#1


22  

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

以下是检查MPMoviePlayerPlaybackDidFinishReasonUserInfoKey的方法,这是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
    }
}

#2


3  

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
    }
}

#3


2  

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.

收到通知后,您可以查看播放器的endPlaybackTime。如果它是-1那么电影自然地完成了。

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

对于流内容,您可以检查MPMoviePlayerPlaybackDidFinishNotification上userInfo内的MPMoviePlayerPlaybackDidFinishReasonUserInfoKey。

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

如果它等于MPMovieFinishReasonUserExited那么它就是用户停止播放内容。

#4


0  

Make sure for

确保

    moviePlayer.repeatMode = MPMovieRepeatModeNone;