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

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