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];
}
答案 0 :(得分:6)
您正尝试从MPMovePlayerViewController
收到通知,但我确信只有MPMoviePlayerController
才能提供通知。尝试并更改您的通知设置
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController.moviePlayer];