首先,MPMoviePlayerController 与 MPMoviePlayer*View*Controller 略有不同,因此在转换构建于 iOS 4.3+ 环境中的应用程序时,其中一些答案会导致问题。
我使用 MPMoviePlayerController 构建了一些应用程序,这些应用程序在 iOS 3.2 中运行良好。当我使用 XCode 3.2.6 (iOS 4.3) 重建它时,视频甚至无法在 iPhone 上播放。此后,我通过将 MPMoviePlayerController 实例添加到子视图来解决此问题,然后在 fullScreenMode 中显示带有 movplayer 的模式(播放器是 UIViewController):
//from didSelectRowAtIndexPath
Vid *selected = [items objectAtIndex:position];
player = [[Player alloc] init];
movplayer = [[MPMoviePlayerController alloc] initWithContentURL:selected.vidURL];
movplayer.view.frame = player.view.bounds;
movplayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[player.view addSubview:movplayer.view];
[self presentModalViewController:player animated:YES];
[movplayer setFullscreen:YES animated:NO];
[movplayer play];
[player release];
//movplayer is released inside - (void)exitedFullscreen:(NSNotification*)notification
这是因为 UINavigationBar 在旋转时被半截掉。
当我使用 iPad 版本的应用程序时,模态选项在美学上不起作用。在全屏模式下旋转时,UISplitViewController navBar 和工具栏也被截断了一半。所以我尝试实现 MPMoviePlayerViewController 而不是 MPMoviePlayerController。通过这种转换,XCode 在尝试设置时给了我错误:
movplayer.controlStyle = MPMovieControlStyleEmbedded;
使用 MPMoviePlayerViewController 执行此操作的正确方法是:
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
当播放器作为子视图添加时,捏合手势将在全屏和父视图 (player.view.bounds) 的大小之间平滑切换播放器,并保留父视图原生的工具栏和导航栏。
//iPad version with a view (viewForMovie) inside the DetailViewController
movplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[current vidURL]];
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
movplayer.view.backgroundColor = [UIColor clearColor];
movplayer.view.frame = viewForMovie.bounds;
[viewForMovie addSubview:movplayer.view];
因此,这两个示例为想要将其 iPhone 或 iPad 应用程序转换为更新的 iOS 版本的用户展示了一些解决方法。