4

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

4

2 回答 2

16

我有同样的问题,我所做的就是让 player 成为一个强大的属性并合成它。有效。

也应该适用于您的情况。!

于 2012-05-03T20:02:12.800 回答
0

决定并使用其中一个MPMoviePlayerViewController MPMoviePlayerController两个,但不能同时使用。

NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"VIDEO_CX75_01" ofType:@"mp4"]];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:myURL];        
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];

或者

NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"VIDEO_CX75_01" ofType:@"mp4"]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];
player.view.frame = self.view.bounds;
[self.view addSubview:player.view];
player.initialPlaybackTime = -1.0;
[player prepareToPlay];
[player play];
于 2012-04-26T21:50:15.200 回答