我正在为AVURLAsset的一种方法准备URL
+ (AVURLAsset *)URLAssetWithURL:(NSURL *)URL options:(NSDictionary *)options
我的URL属于一个文件,该文件被写入我的应用程序的文档路径。NSLog的结果路径是:
/var/mobile/Containers/Data/Application/E0E64E72-9A47-4E62-B9C6-818AB8BF3F4C/Documents/audio.wav
获得NSString *path后,我尝试通过[NSURL URLWithString:path]和[NSURL fileURLWithPath:path]将NSString转换为NSURL,但这两种方法都不适合URLAssetWithURL。
URLWithString的错误是:
错误Domain=AVFoundationErrorDomain代码=-11800“操作无法完成”UserInfo=0x170269f80 {NSUnderlyingError=0x17405f440“操作无法完成。(OSStatus错误-12780.)",发生NSLocalizedFailureReason=An未知错误(-12780),NSLocalizedDescription=The操作无法完成}
fileURLWithPath把应用程序给毁了。
我知道url = [[NSBundle mainBundle] URLForResource:fileURL withExtension:@"wav"]适合这种情况。但是我也想获得本地文件的url以适应URLAssetWithURL。有什么想法吗?谢谢。
发布于 2015-03-05 14:54:09
这种从文档中获取文件的方法应该有效:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths.firstObject stringByAppendingPathComponent:@"file"] stringByAppendingPathExtension:@"wav"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSURL *url = [NSURL fileURLWithPath:path];
}https://stackoverflow.com/questions/28880348
复制相似问题