我试图检索我保存在相册中的视频文件,以便在表视图控制器中显示它。我一直在寻找答案,但我似乎无法找到答案。
我将其保存到相册的功能如下所示:
@IBAction func saveToAlbum(_ sender: Any) {
UISaveVideoAtPathToSavedPhotosAlbum((completedMoviePath?.path)!, nil, nil, nil)
}
似乎没有可以检索保存的视频的功能。有人可以指导我吗?
答案 0 :(得分:0)
像这样使用它在swift 3中为我工作很好
let library = ALAssetsLibrary()
let outputURL = UserDefaults.standard.object(forKey: "url")
if library.videoAtPathIs(compatibleWithSavedPhotosAlbum: outputURL as! URL!) {
library.writeVideoAtPath(toSavedPhotosAlbum: outputURL as! URL!,completionBlock: { (assetURL:URL?, error:Error?) -> Void in
//writeVideoAtPath(toSavedPhotosAlbum: outputURL,completionBlock: { (assetURL:URL!, error:Error?) -> Void in
var title = ""
var message = ""
if error != nil {
title = "Error"
message = "Failed to save video"
} else {
title = "Success"
message = "Video saved"
}
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
})
}