0
votes

I just added Http streaming to my iOS app. I'm using mpmovieplayercontroller I'm having trouble, when the movie ends the player doesn't dismiss

when I had the player pointing to a .mp4 it dismissed just fine. but now i have it pointed to a .m3u8 file. It stops playing one second from the end. (-0:01) even if it does get to the end (0:00) the player still doesn't dismiss.

my code is below

-(void)playmovie
{
 NSURL *url = [NSURL URLWithString:self.videoitem];

    self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

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

    // Register to receive a notification that the movie is now in memory and ready to play
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieLoadStateDidChange:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:nil];

    self.moviePlayer.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self.view addSubview:self.moviePlayer.view];
}



- (void)movieFinishedCallback:(NSNotification*)Notification

{
    MPMoviePlayerController *moviePlayervc = [Notification object];

    // Remove this class from the observers
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayervc];

    // Dismiss the view controller
    [self dismissViewControllerAnimated:YES completion:nil];

}

thank you for any help you can give me.

1
Not to ask stupid questions but are you sure you have the delegate set correctly, and that you have stated that your class adheres to the protocol?Woodstock
yes, everything like that is setup. The thing I don't understand is when i am pointing to a .mp4 and it gets to the end it dismisses just fine. Is there something different when your doing http streaming?user1184205
@JohnWoods it doesn't use delegates. He is using notifications for callbacksKunal Balani

1 Answers

1
votes

m3u8 is not an video file but a part of payload for HTTP live streaming. It waits for certain headers for video completion which is not found my media player. You might want to listen to MPMoviePlayerPlaybackStateDidChangeNotification and check which state it enters when file is completed.

Most probably state should be MPMoviePlaybackStatePaused when the file is complete.