【问题标题】:MPMoviePlayer PlaybackEnd notification receive only onceMPMoviePlayer PlaybackEnd 通知只接收一次
【发布时间】:2014-08-14 11:55:46
【问题描述】:

我的应用有一个带有电影播放器​​的视图。它播放来自互联网的流。我注册 MPMoviePlayerPlaybackDidFinishNotification 以捕获失败。我为播放器实现了自定义 UI,以便用户可以开始播放和暂停播放。这是我的代码

-(void)setUpPlayer:(NSURL*)urlForBuffer{

    self.playerVC = [[MPMoviePlayerController alloc] initWithContentURL:urlForBuffer];

    // Remove the movie player view controller from the "playback did finish" notification observers
    [[NSNotificationCenter defaultCenter] removeObserver:self.playerVC
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:self.playerVC];

    // Register this class as an observer instead
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:self.playerVC];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moveiPlayBackStateChanged:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:self.playerVC];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerLoadStateChanged:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:self.playerVC];

    [self.playerVC setControlStyle:MPMovieControlStyleNone];
    self.playerVC.movieSourceType = MPMovieSourceTypeStreaming;
    [self.view addSubview:self.playerVC.view];

}

- (void)movieFinishedCallback:(NSNotification*)aNotification{
    NSLog(@"stop playing movie file ");
    // Obtain the reason why the movie playback finished
    NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] ;

    if ([finishReason intValue] == MPMovieFinishReasonPlaybackEnded) {
        //movie finished playin
        NSLog(@"Playback has ended without having an error ");

    }else if ([finishReason intValue] == MPMovieFinishReasonUserExited) {
        //user hit the done button
        NSLog(@"User has clicked done button ");

    }else if ([finishReason intValue] == MPMovieFinishReasonPlaybackError) {
        //error
        NSLog(@"Error has occred while playing moviefile ");

    }

    [self.playerVC stop];
}

我想检查 MPMoviePlayerPlaybackDidFinishNotification 通知是否正常。因此,当播放器流式传输时,我断开了 wifi。我收到通知 movieFinishedCallback: 方法没有任何问题。同样在我的控制台中,它也会打印以下错误消息。

_itemFailedToPlayToEnd: {
    AVPlayerItemFailedToPlayToEndTimeErrorKey = "Error Domain=NSURLErrorDomain Code=-1005 \"The network connection was lost.\" UserInfo=0xc057da0 {NSUnderlyingError=0xc084ce0 \"The operation couldn\U2019t be completed. (OSStatus error -1005.)\", NSLocalizedDescription=The network connection was lost.}";
}

然后我在 Wifi 关闭时再次单击播放按钮(我已在 movieFinishedCallback 中停止播放器:)。然后我没有收到任何通知。但是我的控制台中打印了以下错误。

_itemFailedToPlayToEnd: {
    kind = 1;
    new = 2;
    old = 0;
}

哪里出错了。有什么帮助吗?

【问题讨论】:

    标签: ios objective-c mpmovieplayercontroller


    【解决方案1】:

    在 Wifi 关闭时,给定 URL urlForBuffer 上没有文件。所以请确保给定的 URL 有一个文件。

    【讨论】:

    • 你能告诉我为什么在这种情况下我没有收到通知。
    猜你喜欢
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2021-06-16
    • 2010-12-09
    • 1970-01-01
    相关资源
    最近更新 更多