UIVideoAtPathIsCompatibleWithSavedPhotosAlbum无法打开文件Swift 3

时间:2017-01-21 21:13:57

标签: ios swift swift3 avfoundation

我正在创建一个文件路径并使用以下命令记录:

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 Code = -11829"无法打开"   UserInfo = {NSLocalizedFailureReason =此媒体可能已损坏。,   NSLocalizedDescription =无法打开,   NSURL =文件:///var/mobile/Containers/Data/Application/B24F0CD8-479B-483D-AE20-0ED8040101EC/Documents/temp.MOV,   NSUnderlyingError = 0x170241ef0 {错误域= NSOSStatusErrorDomain   代码= -12848"(null)"}}

1 个答案:

答案 0 :(得分:0)

我已经解决了 - 我在尝试保存文件之前添加了一个延迟并且它有效。该代码现为:

for (var i = 0; i < column.children.length; ++i)
    grid.children[i].children[0].color="green";