1

我必须在应用程序启动时显示一个小的介绍视频,并且我也必须显示启动画面(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];

但是在这个实现中,当将播放器视图添加到视图时,总是会出现黑色闪烁。有什么办法可以避免黑闪?

4

2 回答 2

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];

确保您使用无动画呈现它。

于 2012-08-31T06:38:38.153 回答
0

我认为没有任何方法可以避免这种情况,因为当应用程序尝试执行此行时屏幕会闪烁黑色:

[self.view addSubview:playerController.moviePlayer.view];

或者

[self.window.rootViewController presentModalViewController:self.playerController animated:NO];

因此,我认为在执行此执行期间您无能为力。

于 2012-09-04T07:46:27.003 回答