I have a scenario where the notifications for MPMoviewPlayerController
are not being called.
Please check the below code and let me know the issue:
- (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];
}
I am not sure where I set the notifications wrong.