iphone - 从 didFinishLaunchingWithOptions 播放电影

标签 iphone objective-c ios cocoa-touch mpmovieplayercontroller

我的问题是:我的应用程序有一个简短的介绍影片,我想在应用程序启动时显示它,问题是我没有成功。

我在“didFinishLaunchingWithOptions”方法上使用这段代码:

 MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"launch" ofType:@"mov"]]];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.frame = _window.bounds;
moviePlayer.scalingMode = MPMovieScalingModeFill;
[_window addSubview:moviePlayer.view];
[_window makeKeyAndVisible];
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer play];

最好的问候

最佳答案

您应该做的是在您的 RootViewControllerviewDidAppear 方法中删除该代码。或者显示任何其他 View Controller 。这种事情不属于应用程序委托(delegate),您也不应该将 subview 直接添加到您的 UIWindow 实例。

将代码放在 View Controller 中,并将 MPMoviePlayerController 的 View 作为 subview 添加到 self.view 中,它应该可以正常工作。

关于iphone - 从 didFinishLaunchingWithOptions 播放电影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9622519/

相关文章:

iphone - Xcode 6 Beta 工具链错误

objective-c - 为什么不能在 id 上使用点符号,而常规语法可以?

ios - 以编程方式从 subview 快速返回按键按下事件

iPhone : Insert Contact to Address book without any User Interface

iPhone:UIWebview渐变背景在内容向下滚动时重新开始

iphone - 在 iPhone 模拟器中部署测试资源

objective-c - Swift 函数包含在 Objective-C 类中不可用的参数

ios - 测试 HTTPS 身份验证

ios - NSIncrementalStore 子类中的乐观锁定支持

iphone - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : 'executeFetchRequest:error: A fetch request must have an entity.'