iphone - 在 iOS 应用程序 : audio but no picture 中播放视频

标签 iphone video audio

我想在我的 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];

最佳答案

不要混淆 MPMoviePlayerControllerMPMoviePlayerViewController。当您使用 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/

相关文章:

javascript - JavaScript 中的 FFMPEG 命令

java - 使用音频信号创建随 secret 钥

iphone - uitableview 每行显示 3 个对象

iphone - ABPerson 中发短信的默认电话号码

video - 仅提取已更改的帧的一部分

javascript - 多个音频 html : auto stop other when current is playing with javascript

python - 如何使用 audioop 来平均声音数据

iphone - 使用 Facebook iOS SDK 在用户的墙上发布照片

iphone - 如何让iPhone在关闭后再次显示位置授权弹窗?

Android Facebook Video Upload with Graph API - 如何使用 multipart/form-data