iphone - iOS 使用 MPMoviePlayerController 播放视频

标签 iphone ios ios5 ios6 ios6.1

我得到了这段代码:

theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:@"/Resources/disc.mp4"]];
    theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
    theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
    UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
    [theMoviPlayer.view setFrame:backgroundWindow.frame];
    [backgroundWindow addSubview:theMoviPlayer.view];
    [theMoviPlayer play];

但我真的不知道如何将视频添加到我的项目中。我必须将视频文件放在哪个文件夹中!?或者我是否必须执行其他操作才能将其添加到我的项目中?

编辑:

在xcode中看起来是这样的,对吗? 因为我现在确实遇到播放错误。 以前我使用一个 url 来播放这个视频并且效果很好,但是这个文件在本地没有 :(

enter image description here

最佳答案

好的,您的 bundle 路径看起来很麻烦,下面应该可以工作。

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"disc" ofType:@"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];

theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[theMoviPlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:theMoviPlayer.view];
[theMoviPlayer play];

关于iphone - iOS 使用 MPMoviePlayerController 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17578965/

相关文章:

iphone - Xcode 版本 4.6.2 (4H1003) 编译器错误

iphone - 初学者在 iPhone 上常犯的多线程错误

opengl-es - CITemperatureAndTint 具有矢量输入是怎么回事?

ios - 当我在 Story Boards 中命名我的类(class)时黑屏

iphone - 无法播放网络音频文件

像IOS一样的安卓年历

iphone - 从 Iphone native 客户端使用 Google App Engine 进行身份验证

ios - 一个新的 TableView 位于另一个 TableView 之后

ios - 将新单元格添加到 Collection View 时,我不断收到布局错误

ios - 如何测试项目中的私有(private)或文件私有(private)函数