我使用以下代码呈现一个 MPMovieViewController:
NSString *path = [[NSBundle mainBundle] pathForResource:@"Tutorial" ofType:@"m4v"];
// If path is NULL (the resource does not exist) return to avoid crash
if (path == NULL)
return;
NSURL *url = [NSURL fileURLWithPath:path];
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
mpViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
mpViewController.moviePlayer.shouldAutoplay = YES;
// NOTE: This can crash the app in the Simulator. This is a known bug
// in xcode: http://stackoverflow.com/a/8317546/472344
[self presentMoviePlayerViewControllerAnimated:mpViewController];
这在 iOS 4.3 及更高版本中运行良好,但我已经让某人在运行 iOS 4.2.1 的设备上对其进行了测试,并且电影播放器 View Controller 出现,但立即自行消失。我在文档中找不到任何可以解释这一点的内容。有人有什么想法吗?
最佳答案
这听起来很像是电影内容本身的不兼容。
我怀疑 iOS 4.2.1 设备是 iPhone 3G。 3G 支持的编解码器不如最新型号那么多。
iOS4.2.1(及以下版本)的 iPhone 3G 不支持 Main Profile,仅支持 Baseline Profile。
长话短说,您尝试播放的视频与设备不兼容,您需要使用 H264 的基线配置文件对其重新编码。
下面是 Apple 完成的兼容性与编码矩阵。尽管这标题为 HTTP 流媒体编码建议,但它仍然适用于非流媒体(渐进式下载)和本地播放。
关于ios - MPMoviePlayerViewController 在 iOS 4.2 中立即自行解雇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11993107/