MPMoviePlayer-Notification不会被调用

时间:2010-12-14 22:13:48

标签: iphone notifications mpmovieplayercontroller

HI,

我想使用MPMoviePlayerViewController播放电影并收听MPMoviePlayerPlaybackDidFinishNotification,但它不会被调用。有什么想法吗? 得到任何提示都会有所帮助..谢谢你 这是我的代码:

NSString *url   =   [[NSBundle mainBundle] pathForResource:[sender contentName] ofType:@"m4v"];
    MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];

    moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    [self presentMoviePlayerViewControllerAnimated:moviePlayerController];
    [moviePlayerController.moviePlayer play]; 
}


- (void) moviePlayBackComplete:(NSNotification*) notification {
    NSLog(@"moviePlayBackComplete complete");

    MPMoviePlayerController* moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];  

    [self dismissMoviePlayerViewControllerAnimated];
    [moviePlayerController release];
}

1 个答案:

答案 0 :(得分:6)

您正尝试从MPMovePlayerViewController收到通知,但我确信只有MPMoviePlayerController才能提供通知。尝试并更改您的通知设置

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController.moviePlayer];