我正在创建一个文件路径并将其记录为:
filePath = documentsURL.appendingPathComponent("temp.MOV")
videoFileOutput.startRecording(toOutputFileURL: filePath, recordingDelegate: recordingDelegate)然后我停止录音,然后
let mediaLocation = (filePath).path
if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(mediaLocation) {
UISaveVideoAtPathToSavedPhotosAlbum(mediaLocation, self, nil, nil)
} else {
print("Cannot find file to save")
let player = AVPlayer(url: filePath)
let playerController = AVPlayerViewController()
playerController.showsPlaybackControls = true
playerController.player = player
present(playerController, animated: false) {
player.play()
}
}如果将媒体位置保持为String(describing: filePath),则错误是“找不到文件”,但播放机将打开文件。如果使用上述代码,则错误为“无法打开”,但播放机将播放该文件。
完全错误是:
视频/var/mobile/Containers/Data/Application/B24F0CD8-479B-483D-AE20-0ED8040101EC/Documents/temp.MOV无法保存到保存的相册:错误Domain=AVFoundationErrorDomain代码=-11829“无法打开”UserInfo={NSLocalizedFailureReason=This媒体可能损坏。,NSLocalizedDescription=Cannot打开,NSURL=file:///var/mobile/Containers/Data/Application/B24F0CD8-479B-483D-AE20-0ED8040101EC/Documents/temp.MOV,NSUnderlyingError=0x170241ef0 {错误Domain=NSOSStatusErrorDomain代码=-12848 "(null)"}}
发布于 2017-01-22 12:40:00
我已经解决了它-我在试图保存文件之前添加了一个延迟,而且它成功了。该守则现在内容如下:
let when = DispatchTime.now() + 0.1 // change 0.1 to desired number of seconds
DispatchQueue.main.asyncAfter(deadline: when) {
if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(mediaLocation!) {
UISaveVideoAtPathToSavedPhotosAlbum(mediaLocation!, self, nil, nil)
} else {
print("Cannot find file to save")
}
}https://stackoverflow.com/questions/41784581
复制相似问题