简体   繁体   中英

MPMoviePlayerViewController called from UITabBarController doesn't send notifications in IOS5

I had an app that worked fine in IOS4 but stopped displaying videos in IOS5. Previously I was using MPMoviePlayerController, so I switched to MPMoviePlayerViewController and now the videos display fine in IOS5.

But, now in IOS5, when the Done button is pressed the video stops playing in MPMoviePlayerViewController, but the MPMoviePlayerController no longer calls Notifications.

The hierarchy looks like:

AppDelegate -> UITabBarController -> UITableView -> UIViewController within which the MPMoviePlayerViewController is called. Inside the UIViewController the code looks like:

MPMoviePlayerViewController *tmpMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
self.moviePlayer = tmpMoviePlayer;

[self presentMoviePlayerViewControllerAnimated:self.moviePlayer];

NSNotificationCenter *notificationCenter = [ NSNotificationCenter defaultCenter ];
[notificationCenter addObserver:self  
                       selector:@selector(moviePlayerPlaybackDidFinish:)  
                           name:MPMoviePlayerWillExitFullscreenNotification  
                         object:[self.moviePlayer moviePlayer ]]; 

I've also tried the following notification names and none of them get triggered:

 MPMoviePlayerPlaybackDidFinishNotification 
 MPMoviePlayerPlaybackStateDidChangeNotification
 MPMoviePlayerPlaybackDidFinishReasonUserInfoKey
 MPMoviePlayerNowPlayingMovieDidChangeNotification
 MPMoviePlayerWillExitFullscreenNotification
 MPMoviePlayerDidExitFullscreenNotification

I have seen a SO posting where the MPMoviePlayerViewController was called from within a UITabBarController and the view that called presentMoviePlayerViewControllerAnimated wasn't selected correctly, but I haven't been able to get any other view to work for calling presentMoviePlayerViewControllerAnimated.

Any ideas why the notifications are no longer called when the Done button of MPMoviePlayerViewController is pressed?

I did solve this but I can't remember what the fix actually was. But I can show the code that works now:

[ notificationCenter addObserver: self 
                            selector:@selector(moviePlayerPlaybackDidFinish:) 
                            name: MPMoviePlayerPlaybackDidFinishNotification 
                            object: moviePlayer ];


self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.shouldAutoplay = NO;  
[self.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[[self view] addSubview:[self.moviePlayer view]];   
[self.moviePlayer setFullscreen:YES animated:YES];
[self.moviePlayer play];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM