视频失败时MPMoviePlayerPlaybackDidFinishNotification

时间:2015-01-30 11:53:35

标签: ios mpmovieplayercontroller

MPMoviePlayerController由于错误或视频结束时播放结束时,我需要有所作为。我使用像我这样处理的MPMoviePlayerPlaybackDidFinishNotification

- (void)moviePlayerPlaybackDidFinish:(NSNotification *)notification
{
    NSDictionary *notificationUserInfo = [notification userInfo];
    NSNumber *resultValue = notificationUserInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
    MPMovieFinishReason reason = (MPMovieFinishReason) [resultValue intValue];
    if (reason == MPMovieFinishReasonPlaybackError) {
        NSLog(@"playback failed without any given reason");

    }
    if (reason == MPMovieFinishReasonPlaybackEnded) {
        NSLog(@"playback ended");
    }
}

问题是即使视频失败,MPMovieFinishReason仍为MPMovieFinishReasonPlaybackEnded

当我的视频失败时,我注意到在AVPlayerItemFailedToPlayToEndTimeNotification之前发布了MPMoviePlayerPlaybackDidFinishNotification。它包含此用户信息

{
    AVPlayerItemFailedToPlayToEndTimeErrorKey = "Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not be completed\" UserInfo=0x78f621c0 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x794f3a30 \"The operation couldn\U2019t be completed. (OSStatus error -12551.)\", NSLocalizedFailureReason=An unknown error occurred (-12551)}";
}

我可以将它用作解决方法,因此在我的控制器中设置一个状态,例如self.failedToPlayToEnd = YES;然后在我的moviePlayerPlaybackDidFinish方法中使用它。这似乎不对,因为没有什么能保证我这两个通知的顺序。

所以问题是,如何确定视频无法播放。顺便说一句,我说的是当播放失败时它没有停止。

Here is the video在结束前2秒失败

0 个答案:

没有答案