问题总结
在使用 MPMoviePlayerViewController 播放视频时更改 iPad 设备或模拟器的方向会导致视频播放器关闭时旋转状态不一致。这是 iPad SDK 3.2 中的一个已知错误,记录在 http://www.openradar.me/8012810。
示例项目
我已经使用 Xcode 3.2.2 中基于 View 的应用程序模板准备了一个最小的示例项目,使用以下代码启动播放器
NSURL *movieUrl = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
[self presentMoviePlayerViewControllerAnimated:player];
[player release];
代码在 GitHub 上可用 http://github.com/adamalex/FullScreenMovie或使用 http://github.com/adamalex/FullScreenMovie/zipball/master 直接下载
重现步骤
- 使用以上信息获取项目
- 使用 iPad 模拟器或设备启动项目
- 点击按钮开始播放视频
- 将 iPad 旋转 90 度
- 关闭视频
- 注意 UIStatusBar 与应用程序 UI 不同步
目标
我已联系 Apple,他们已确认这是一个正在调查中的错误。我想讨论使用公共(public) API 安全提交到 App Store 的临时解决方法。我还将向 Apple 提交一个开发者支持案例,并将报告我自己的进展。
最佳答案
Apple Developer Technical Support 的成功响应!
This is a known bug and a we're received a number of duplicate bug reports and so iOS engineering is aware of the issue and we do have a temporary workaround as suggested by iOS engineering.
You will need to implement this in the view controller which presents the movie player.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[self performSelector:@selector(fixStatusBar) withObject:nil afterDelay:0];
}
- (void)fixStatusBar {
[[UIApplication sharedApplication] setStatusBarOrientation:[self interfaceOrientation] animated:NO];
}
While this is somewhat ugly, it should fix the issue for now. It would be recommended to remove this code once the bug is fixed in the system.
这完全解决了我的问题,您可以重新访问 http://github.com/adamalex/FullScreenMovie对于应用了修复程序的代码。
关于iphone - 使用 MPMoviePlayerViewController 时 iPad 旋转错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3089692/