1

我想用 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?谢谢

4

1 回答 1

2

iOS 6 的 MediaPlayer.framework 中似乎存在错误。为了让视频播放,我prepareToPlay在初始化 MPMoviePlayerViewController 后调用

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];
}
于 2012-11-01T10:47:48.850 回答