Reputation: 43
I am trying to load a video downloaded from the internet stored in the Documents directory. However when I try I keep getting: error: Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
let dstURL = URL(string: dstPath)!
let asset = AVAsset(url: dstURL)
asset.loadValuesAsynchronously(forKeys: ["tracks", "playable"]) {
var error: NSError?
let status = asset.statusOfValue(forKey: "tracks", error: &error)
if error != nil {
print("status: \(status), error: \(error!)")
}
}
Upvotes: 2
Views: 930
Reputation: 105
While you can use URL(fileURLWithPath:)
, it has been deprecated on almost every platform (e.g. since macOS 13.3). You should be using URL(string:)
instead and make very sure that your URL is complete (i.e. does it have a scheme?)
As an example,
guard var components = URLComponents(string: path) else {
throw UserError.invalidPath(path)
}
// We're assuming that `path` didn't have this set (e.g. it's an absolute path and just assumes).
components.scheme = "file"
guard let url = components.url else {
throw UserError.invalidPath(path)
}
return url
Upvotes: 0