在我的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/