【发布时间】:2019-11-26 04:17:39
【问题描述】:
我想下载音频文件,保存在照片库中,下载后播放。但是这段代码没有将视频保存在库中。
是否可以直接在照片库或外部任何其他文件夹中下载。
我的代码来自这里Swift - Download a video from distant URL and save it in an photo album
DispatchQueue.global(qos: .background).async {
if let url = URL(string: self.audioURL!),
let urlData = NSData(contentsOf: url) {
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
let filePath="\(documentsPath)/tempFile.mp3"
print(filePath)
DispatchQueue.main.async {
urlData.write(toFile: filePath, atomically: true)
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: URL(fileURLWithPath: filePath))
}) { completed, error in
if completed {
print("Video is saved!")
}
}
}
}
}
【问题讨论】:
-
有什么问题
-
这个是不是下载我不知道,它存储在哪里,它在照片中不可见。
标签: ios swift xcode cocoa-touch avaudioplayer