Ios5 初始化并播放MPMoviePlayerController返回黑屏

Ios5 初始化并播放MPMoviePlayerController返回黑屏,ios5,mpmovieplayercontroller,xcode4.3,Ios5,Mpmovieplayercontroller,Xcode4.3,我正在尝试使用Xcode中的一些示例代码在iPhone模拟器5.1下播放mp4视频。我创建了MPMovieViewController和MPMovieController,提供了一个包含mp4的本地路径,并将其作为子视图添加到我的根控制器中 当我在iPhone模拟器下运行它时,只显示背面屏幕。我在SO中尝试了几个相同问题的建议,但仍然不起作用 代码如下: NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBu

我正在尝试使用Xcode中的一些示例代码在iPhone模拟器5.1下播放mp4视频。我创建了MPMovieViewController和MPMovieController,提供了一个包含mp4的本地路径,并将其作为子视图添加到我的根控制器中

当我在iPhone模拟器下运行它时,只显示背面屏幕。我在SO中尝试了几个相同问题的建议,但仍然不起作用

代码如下:

    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];
我哪里做错了


备注:我使用的是Xcode 4.3.2,决定并使用MPMoviePlayerController或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];

我也遇到了同样的问题,我所做的就是把玩家变成一个强大的属性并合成它。成功了


在你的情况下也应该有效

这两种方法都试过了,但似乎都不起作用,黑屏仍然显示,而不是电影画面。PS:我已经添加了MediaPlayer.framework,可以通过QuickTime确认mp4电影正在播放。谢谢!一瞬间,我就猜不到了。(只要将视图添加到另一个屏幕视图中,其他视图及其视图控制器就会被保留,但显然这一个没有。或者我还没有在屏幕上显示父视图。不确定。)天哪!谢谢。我在这件事上坚持了4天。非常感谢你。