我正在尝试使用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];
我做错了什么?
PS:我在使用Xcode 4.3.2
答案 0 :(得分:16)
我遇到了同样的问题,而我所做的就是让玩家成为一个强大的属性并合成它。有效。
也适用于您的情况。!
答案 1 :(得分:0)
决定并使用MPMoviePlayerViewController
或 MPMoviePlayerController
,但不能同时使用。{/ p>
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];