0

My app has a view with Movie Player. Which plays a stream from the internet. I register for MPMoviePlayerPlaybackDidFinishNotification to capture failures. I implement custom UI to the player so that user can start the play and pause it. Here is my code

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

I want to check MPMoviePlayerPlaybackDidFinishNotification notification works fine. So when player streaming I disconnect the wifi. I received the notification movieFinishedCallback: method without any problem. Also in my console it prints following error message as well.

_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.}";
}

Then I clicked the play button again while Wifi is off (I have stop the player in movieFinishedCallback:). Then I did not receive any notification. But following error has printed in my console.

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

Where did it go wrong. Any help?

1 Answer 1

0

There is no file located on the given URL urlForBuffer while Wifi is off. So make sure there is a file at the given URL.

1
  • Can you tell me why I did not receive the notification in that case.
    – nath
    Aug 15, 2014 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.