我想在我的 iPhone 应用程序中播放一段短片。当我使用下面的代码时,我只能听到音频并看到 应用程序的常规 View 。我希望视频在此 View 之上播放。 我该怎么办?
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"LEADER" ofType:@"mov"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
最佳答案
不要混淆 MPMoviePlayerController
和 MPMoviePlayerViewController
。当您使用 MPMoviePlayerController
时,请像这样使用它(通常用于 iPad 上的嵌入式视频):
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
当您使用 MPMoviePlayerViewController
时,然后使用 presentMoviePlayerViewControllerAnimated:
呈现视频:(通常用于全屏视频)。
关于iphone - 在 iOS 应用程序 : audio but no picture 中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5337900/