2012-08-31 49 views
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]; 

但是這個實現總是有當播放器視圖添加到視圖中的黑色閃光。有什麼辦法可以避免黑色閃光?

回答

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

請確保您將它與無動畫一起呈現。

+0

Manish感謝您的期待,但它沒有幫助。 – Soni

0

我不認爲有什麼辦法避免這一點,因爲在屏幕上閃爍的黑色,當應用程序試圖執行這一行:

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

OR

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

所以我認爲沒有什麼你可以在這個執行時做。

相關問題