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
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.!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With