在我的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]];
感谢您的帮助!
答案 0 :(得分:5)
文件肯定在主包中吗?
尝试使用此方法获取网址。
NSURL *url = [[NSBundle mainBundle] URLForResource:@"myMovie" withExtension:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];