I am preparing the URL for one method of AVURLAsset
:
+ (AVURLAsset *)URLAssetWithURL:(NSURL *)URL options:(NSDictionary *)options
My URL belongs to a file which is written to the document path of my app. The result of NSLog
the path is:
/var/mobile/Containers/Data/Application/E0E64E72-9A47-4E62-B9C6-818AB8BF3F4C/Documents/audio.wav
After got the NSString *path
, I tried to convert NSString to NSURL by [NSURL URLWithString:path]
and [NSURL fileURLWithPath:path]
, but both of them are incorrect for URLAssetWithURL
.
Error of URLWithString
is:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x170269f80 {NSUnderlyingError=0x17405f440 "The operation couldn’t be completed. (OSStatus error -12780.)", NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed}
And fileURLWithPath
crashed the app.
I know url = [[NSBundle mainBundle] URLForResource:fileURL withExtension:@"wav"]
will fit the situation. But I want to get the url of a local file to fit URLAssetWithURL
as well. Any idea? Thanks.
fileURLWithPath
is the right way to convert path to a file URL. You say it "crashed the app". What precisely happened? Did the file URL look OK? Did you confirm that the file was actually found at that location? – Rob