1

I'm using MPMoviePlayerViewController to show a video in my app. It works! Only problem is that there's a black flash just before the movie plays.

How can I get rid of the black flash? I've seen other threads, but they don't seem to have an explanation that works with MPMoviePlayerViewController and is sufficiently specific/detailed for a novice like me (most are for MPMoviePlayerController).

Would really appreciate any help!

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"aiw_intro_video" ofType:@"mp4"];
NSURL    *fileURL = [NSURL fileURLWithPath:filepath];

MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] init];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
mpvc.moviePlayer.controlStyle = MPMovieControlStyleNone;
[mpvc.moviePlayer setContentURL:fileURL];
[mpvc.moviePlayer play];

[self presentViewController:mpvc animated:NO completion:NULL];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:mpvc.moviePlayer];
  • What happens if you delete `[mpvc.moviePlayer play];`? It should start playing anyway so that line is not needed. Also why not say `animated:YES`? This will help give things time to get started. – matt Jan 21 '15 at 21:06
  • Thanks, Matt. I made those changes. Plays just fine but still a black flash at the beginning. – Parker Barrile Jan 21 '15 at 21:18
  • The answer here worked for me: http://stackoverflow.com/questions/4216021/mpmovieplayercontroller-causes-flash-of-black-at-start-of-video – Ultrasaurus Jun 06 '15 at 14:29

1 Answers1

2

After endlessly iterating and tweaking, I stumbled my way into a solution using MPMoviePlayerController.

Don't forget to declare the property in the .h file, e.g.

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

Then

// Add default image to smooth transition
UIImage *myImage = [UIImage imageNamed:@"aiw_launch1136_black.png"];
self.videoStartFrame.image = myImage;

// Play the intro video
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"aiw_intro_video" ofType:@"mp4"]]];

self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
[self.moviePlayer.view setFrame:self.view.bounds];

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

self.moviePlayer.view.hidden = YES;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isMovieReady:) name:MPMoviePlayerLoadStateDidChangeNotification object:self.moviePlayer];


// Detect that the video is ready and unhide the view

-(void)isMovieReady:(NSNotification *)notification {

MPMoviePlayerController *moviePlayer = [notification object];

if(moviePlayer.loadState & (MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK))
    {
    self.moviePlayer.view.hidden = NO;
    }
}