我的应用程序在IOS4中运行良好,但在IOS5中停止显示视频。以前我使用MPMoviePlayerController,所以我切换到MPMoviePlayerViewController,现在视频在IOS5中显示正常。
但是,现在在IOS5中,当按下完成按钮时,视频停止在MPMoviePlayerViewController中播放,但MPMoviePlayerController不再调用通知。
层次结构如下:
AppDelegate - > UITabBarController - > UITableView - >调用MPMoviePlayerViewController的UIViewController。在UIViewController中,代码如下:
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 ]];
我还尝试了以下通知名称,但没有一个被触发:
MPMoviePlayerPlaybackDidFinishNotification
MPMoviePlayerPlaybackStateDidChangeNotification
MPMoviePlayerPlaybackDidFinishReasonUserInfoKey
MPMoviePlayerNowPlayingMovieDidChangeNotification
MPMoviePlayerWillExitFullscreenNotification
MPMoviePlayerDidExitFullscreenNotification
我看过一个SO posting,其中从UITabBarController中调用了MPMoviePlayerViewController,并且没有正确选择调用presentMoviePlayerViewControllerAnimated的视图,但是我无法让任何其他视图用于调用presentMoviePlayerViewControllerAnimated。
当按下MPMoviePlayerViewController的Done按钮时,为什么不再调用通知的任何想法?
答案 0 :(得分:0)
我确实解决了这个问题,但我不记得实际修复了什么。但我可以展示现在有效的代码:
[ 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];