ios - 如何在 iOS 上播放电影

标签 ios cocoa-touch cocos2d-iphone mpmovieplayercontroller

所以我创建了一个 View ,其中有一个可以播放电影的按钮。

这是该按钮的操作:

- (IBAction)playMovie {

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"sample_iPod" ofType:@"m4v"];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];
}

然而,当我测试应用程序并尝试播放视频时,屏幕保持空白,并且在日志中显示如下:

[切换到进程9333线程0x13c03]

知道怎么回事吗?

谢谢

最佳答案

需要设置播放器的bounds,并将播放器的 View 添加到self.view:

 [theMovie.view setFrame: self.view.bounds];  // player's frame must match parent's
 [self.view addSubview: theMovie.view];

关于ios - 如何在 iOS 上播放电影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9089075/

相关文章:

ios - 您如何管理 iOS 项目中的 View 标签?

objective-c - Dealloc 未被调用

ios - b2Body 移动时更新 CC Sprite 位置?

objective-c - 如何在cocos2d和iOS中使用plist文件?

ios - UIViewController 和 NSURLConnection

javascript - 为什么我得到 "undefined is not an object (evaluating PropTypes.shape)"?

iphone - 保留 iOS 4 中所有本地推送通知的列表

objective-c - Objective C - 函数(不知道如何解释这个)

ios - SKPSMTP消息库

ios - 不覆盖 UILabel 的文本属性