修复录音无法播放问题

This commit is contained in:
liyuhua
2024-03-07 18:27:47 +08:00
parent 1eb88acd7f
commit aacae7954f

View File

@@ -68,11 +68,12 @@ class PlayVoiceManager: NSObject,AVAudioPlayerDelegate {
let downloadTask = session.downloadTask(with: request,
completionHandler: { (location:URL?, response:URLResponse?, error:Error?)
-> Void in
let locationPath = location!.path
if FileManager.default.fileExists(atPath: path){
try? FileManager.default.removeItem(atPath: path)
}
guard let locationPath = location?.path else{return}
do {
if FileManager.default.fileExists(atPath: path){
try FileManager.default.removeItem(atPath: path)
}
// document
try FileManager.default.copyItem(atPath: locationPath, toPath: path)
// main
@@ -80,15 +81,8 @@ class PlayVoiceManager: NSObject,AVAudioPlayerDelegate {
self.beginPlayVoice(url:path)
}
} catch let error {
debugPrint(error)
HUDTool.show(with: "\(error.localizedDescription)")
}
// let data = NSData.init(contentsOfFile: locationPath)
// if let _data = data {
// let isHave = _data.write(toFile: path, atomically: true)
// print(isHave)
// self.beginPlayVoice(url:path)
// }
})