我正在开发一款iPad App&目前正在设备上测试它 - 我正在使用sqlite数据库来读取.m4v电影文件的网址。
为了使用模拟器进行测试,我在数据库中列出了URL,如下所示:
/Users/Octave1/Desktop/iDev/Moodymann/IMM Simulator App/Content/Movies/visuals seg0.m4v
.
.
.
这很好用&正确读取数据库,&文件按要求播放。
当我在iPad上运行应用程序时,我将数据库中的URL更改为以下格式:
/Content/Movies/visuals seg0.m4v
.
.
.
然而这部电影根本不播放。似乎路径和路径存在问题。没有找到文件 - 任何人都知道在应用程序本身中引用文件的正确方法吗?
提前致谢:)
答案 0 :(得分:0)
对于有同样问题的人,我想出了这个。
首先 - 我将“Content”文件夹复制到iPad上,并将其放入图书馆目录,如下所示:
//Finding out where the Library Directory is located
NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
//Find where my content folder is initially
NSString *contentPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Content"];
NSError *error = nil;
[[NSFileManager defaultManager] copyItemAtPath:contentPath
toPath:libraryDirectory
error:&error];
if([[NSFileManager defaultManager] copyItemAtPath:contentPath toPath:folderPath error:&error]){
NSLog(@"File successfully copied");
} else {
NSLog(@"Error description-%@ \n", [error localizedDescription]);
NSLog(@"Error reason-%@", [error localizedFailureReason]);
}
然后,我可以读出每部电影的地址,&将每个地址附加到图书馆的地址
NSString *inFilePath = movieObj.pathToMovie; ///Content/Movies/visuals seg0.m4v from above
NSLog(@"inFilePath is: %@", inFilePath);
NSString *fullPath = [libraryDir stringByAppendingPathComponent:[[NSString alloc] initWithString:inFilePath]];
NSLog(@"fullPath is: %@", fullPath);
NSURL *url = [[NSURL alloc] initFileURLWithPath:fullPath];
NSLog(@"url is: %@", url);
[movieUrlArray addObject:url];
现在我知道了应用程序文件系统中电影文件的URL。