Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Init and playing MPMoviePlayerController returns black screen

I am trying to play an mp4 video under iPhone Simulator 5.1 using some sample code from Xcode. I created both MPMovieViewController and MPMovieController, supply a local path which contains the mp4 and add it as subview to my root controller.

When I run it under iPhone Simulator, only back screen shown. I've tried a couple of suggestions of the same problem in SO but still it doesn't work.

Here's the code:

    NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"VIDEO_CX75_01" ofType:@"mp4"]];

    MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:myURL];        
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];

    [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];

    [player.view setFrame: self.view.bounds];  // player's frame must match parent's
    [self.view addSubview: player.view];
    player.view.frame = self.view.frame;

    player.initialPlaybackTime = -1.0;
    [player prepareToPlay];
    [player play];

Where I am doing it wrong?

PS: I am on Xcode 4.3.2

like image 291
Scott Avatar asked Dec 05 '22 16:12

Scott


1 Answers

I had the same problem, and I what I did was made player a strong property and synthesize it. It worked.

Should work in your case as well.!

like image 158
mvb Avatar answered Mar 15 '23 03:03

mvb