我必须在应用启动时显示一个小的介绍视频,我也必须显示启动画面(DEFAULT.png)。 所以在我的第一个视图控制器的viewDidLoad中我做了:
NSURL * movieUrl = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4"]];
self.playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:movieUrl];
//Fit the screen
self.playerController.view.frame = CGRectMake(0, -20, 320, 480);
//Hide video controls
self.playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
//Play as soon as loaded
self.playerController.moviePlayer.shouldAutoplay = YES;
//Add the video as the first view background
[self.view addSubview:playerController.moviePlayer.view];
但是,通过此实现,当视图中添加了播放器视图时,始终会出现黑色闪烁。有没有办法避免黑色闪光?
答案 0 :(得分:2)
不是在firstViewController中呈现playerController,而是在appDelegate中处理它并将其呈现在窗口的rootViewController上。
NSURL * movieUrl = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4"]];
self.playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:movieUrl];
//Fit the screen
self.playerController.view.frame = CGRectMake(0, -20, 320, 480);
//Hide video controls
self.playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
//Play as soon as loaded
self.playerController.moviePlayer.shouldAutoplay = YES;
[self.window.rootViewController presentModalViewController:self.playerController animated:NO];
确保以无动画呈现它。
答案 1 :(得分:0)
我认为没有办法避免这种情况,因为当应用程序尝试执行此行时,屏幕会闪烁黑色:
[self.view addSubview:playerController.moviePlayer.view];
OR
[self.window.rootViewController presentModalViewController:self.playerController animated:NO];
所以我认为在执行时你无能为力。