iphone - MPMoviePlayerPlaybackDidFinishNotification 在不应调用时被调用

标签 iphone ipad mpmovieplayercontroller

根据 Apple 的 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 确实会被调用,但就像我说的,当您点击“完成”时,它也会被调用。

最佳答案

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

关于iphone - MPMoviePlayerPlaybackDidFinishNotification 在不应调用时被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4158453/

相关文章:

ios - 从 MPMoviePlayerController 调整缩略图大小

iphone - 如何释放MPMoviePlayerController?

ios - 可从 iOS 中的锁定屏幕访问的按钮

javascript - 有更好的 Android 支持的 JQTouch 的 JQuery 替代品吗?

ios - 通知 "app started to the background"

ios - 如何调整 Collection View 单元格的大小(可能是 PInterest 应用程序)

iphone - 使用 CALayer 委托(delegate)

ios - 旋转行为 iOS8 与 iOS9

iphone - 使用 NTimer 更新 NSDateFormatter

iphone - MPMoviePlayerController 应该只在横向模式下