views:

92

answers:

3

Can't figure out why I'm not getting my callback - any advice?

-(void) playMovieWithURL:(NSURL *)url {

    [currentVC.view removeFromSuperview];

    MPMoviePlayerViewController *movieControl = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

    //register for playback finished call
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinished:) name:MPMoviePlayerDidExitFullscreenNotification object:movieControl];

    [self presentMoviePlayerViewControllerAnimated:movieControl];       
}

-(void) movieFinished:(NSNotification *)aNotification {

    NSLog(@"received callback that movie finished");

    MPMoviePlayerController *movie = [aNotification object];

    [movie.view removeFromSuperview];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:movie];

    [movie release];

    [self.view addSubview:currentVC.view];      
}
+1  A: 

Wild guess, but maybe you want MPMoviePlayerPlaybackDidFinishNotification instead of MPMoviePlayerDidExitFullscreenNotification ?

Jason Foreman
I've actually tried both and in neither case is my movieFinished function called. However, the reason that I've opted for the DidExitFullScreen instead of DidFinish is because a)my movie is always presented modally b)the DidFinishNotification is only generated if the entire clip plays - so, for example, if the user taps "done" before the clip is over, the DidFinish wouldn't be called, whereas the DidExitFullScreen would be.
isaac
A: 

I don't know much about the MP API, but you're registering for the notification in a reasonable way. Are you sure that MPMoviePlayerDidExitFullscreenNotification is the notification you want? That (by name alone) doesn't appear to be equivalent to "movie finished".

quixoto
Hi - I commented on the previous, but, since two people are suggesting I review the specific notification I'm calling, I'm going to fiddle in that direction.
isaac
A: 

MPMoviePlayerController posts notifications MPMoviePlayerViewController does NOT post notifications

So I suppose I'll just switch over to using MPMoviePlayerControllers in this particular case.

isaac
You could just pass in [movieControl moviePlayer] to get the MPMoviePlayerController that's posting the notifications.
David Liu
Yes that is how I ended up doing it, thanks!
isaac