iphone - 如何正确构建本地电影URL?

标签 iphone objective-c ios ios4 mpmovieplayercontroller

在我的iPhone应用程序中,用户可以单击表格单元格,然后将开始播放电影。这部电影是我项目中“/Resources/myMovie.m4v”下的本地文件。我不知道如何正确链接到它。

我找到了以下代码,但似乎不起作用:

NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent:@"myMovie.m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath:filePath isDirectory:NO]];

谢谢您的帮助!

最佳答案

该文件肯定在主捆绑包中吗?

尝试使用它来获取URL。

NSURL *url = [[NSBundle mainBundle] URLForResource:@"myMovie" withExtension:@"m4v"];
   moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

关于iphone - 如何正确构建本地电影URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5372580/

相关文章:

iphone - 支持 NSString 的国际化

c++ - 从 cvMat 转换为 UIImage 会改变图像

ios - Debug模式不起作用

objective-c - CoreBluetooth 代表主队列/主线程?

ios - 如何让 UIAnimation 一次执行一个(迭代 for 循环),而不是一次执行全部?

iphone - iOS写入文件

ios - StartInterval 键如何影响启动的守护进程

iPhone,拍摄时如何检测图像的方向

ios - 由于 ipv6 将应用程序上传到 Apple Store 时出现问题

ios - 以编程方式滑动 UIScrollView