MPMoviewPlayerController
我有一个没有调用 通知的场景。
请检查以下代码并让我知道问题:
- (void)playVideo:(nsstring *)filePath onController:(UIViewController *)controller {
self.mediaPlayerContainerViewController = [[UIViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.mediaPlayerContainerViewController];
NSURL *videoUrl = [NSURL fileURLWithPath:filePath];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainMovieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallBack:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
self.playerController = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
self.playerController.view.frame = self.mediaPlayerContainerViewController.view.bounds;
[self.playerController setFullscreen:NO animated:NO];
[self.playerController setControlStyle:MPMovieControlStyleEmbedded];
[self.mediaPlayerContainerViewController.view addSubview:self.playerController.view];
[self.playerController prepareToPlay];
self.playerController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.mediaPlayerContainerViewController.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[controller presentViewController:navController animated:YES completion:^(void) {
self.mediaPlayerContainerViewController.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Homebutton.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(dismissMediaPlayerViewController)],
[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ArrowStandardCircle.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(dismissMediaPlayerViewController)],
nil];
[self.playerController play];
}];
}
- (void)movieFinishedCallBack:(NSNotification *) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player stop];
}
我不确定我在哪里设置了错误的通知。