MPMoviePlayerPlaybackDidFinishNotification 在不应调用时被调用

发布于 2024-10-02 03:37:48 字数 618 浏览 0 评论 0原文

根据苹果的 MPMoviePlayerController 文档:

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

在我看来这是完全错误的。使用下面的代码,当我点击完成按钮时,playerPlaybackDidFinish 就会被调用。

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

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

我需要区分用户点击“完成”按钮和电影在播放过程中完成的情况。当电影结束时,playerPlaybackDidFinish 确实会被调用,但就像我说的,当你点击“完成”时它也会被调用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风筝在阴天搁浅。 2024-10-09 03:37:48

以下是检查 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
    }
}

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
    }
}
浊酒尽余欢 2024-10-09 03:37:48

当电影一直播放到最后时,我使用以下方法执行某些操作:

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

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
    }
}
柳絮泡泡 2024-10-09 03:37:48

当您收到通知时,您可以检查播放器的 endPlaybackTime。如果是-1,那么电影就自然结束了。

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

如果它等于 MPMovieFinishReasonUserExited 则表示用户停止播放内容。

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.

对风讲故事 2024-10-09 03:37:48

确保为

    moviePlayer.repeatMode = MPMovieRepeatModeNone;

Make sure for

    moviePlayer.repeatMode = MPMovieRepeatModeNone;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文