我想用MPMoviePlayerViewController播放视频。所以在我的视图控制器中,我注册为MPMoviePlayerLoadStateDidChangeNotification
的观察者。
然后我初始化MPMoviePlayerViewController:
self.mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"<videoURL>"]];
等待通知到达。我什么时候执行这段代码:
MPMoviePlayerController* playerController = notification.object;
if ([playerController loadState] & MPMovieLoadStatePlayable) {
if (self.mPlayerVC) {
[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];
}
}
任何人都知道为什么这适用于iOS 5而不适用于iOS 6?感谢
答案 0 :(得分:2)
iOS 6'MediaPlayer.framework中似乎存在一个错误。要播放视频,我在初始化MPMoviePlayerViewController后调用prepareToPlay
self.mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"<videoURL>"]];
[self.mPlayerVC.moviePlayer prepareToPlay];
现在,通知会再次显示,但是当我在为[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];
调用的方法中调用MPMoviePlayerLoadStateDidChangeNotification
时应用程序崩溃。
防止崩溃替换
[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];
类似
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
[self presentViewController:self.mPlayerVC animated:YES completion:nil];
}
else if ([self respondsToSelector:@selector(presentModalViewController:animated:)]) {
[self presentModalViewController:self.mPlayerVC animated:YES];
}