Soni
Soni

Reputation: 454

Showing Intro Video at app launch

I have to show a small intro video on app launch and I have to show splash screen too (DEFAULT.png). so in viewDidLoad of my first view controller I do :

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

But with this implementation there is always a black flash when player view is added to the view. Is there any way to avoid the black flash ?

Upvotes: 1

Views: 1946

Answers (2)

Soni
Soni

Reputation: 454

I don't think there is any way to avoid this because the screen flashes black when the app tries to execute this line :

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

OR

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

So I think there's nothing you can do while this execution.

Upvotes: 0

Manish Ahuja
Manish Ahuja

Reputation: 4517

Rather than presenting the playerController in your firstViewController, handle this in the appDelegate and present it over window's 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];

Make sure you present it with No animation.

Upvotes: 2

Related Questions