首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIVideoAtPathIsCompatibleWithSavedPhotosAlbum无法打开文件Swift 3

UIVideoAtPathIsCompatibleWithSavedPhotosAlbum无法打开文件Swift 3
EN

Stack Overflow用户
提问于 2017-01-21 21:13:57
回答 1查看 1.4K关注 0票数 0

我正在创建一个文件路径并将其记录为:

代码语言:javascript
复制
filePath = documentsURL.appendingPathComponent("temp.MOV")
videoFileOutput.startRecording(toOutputFileURL: filePath, recordingDelegate: recordingDelegate)

然后我停止录音,然后

代码语言:javascript
复制
  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)"}}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-22 12:40:00

我已经解决了它-我在试图保存文件之前添加了一个延迟,而且它成功了。该守则现在内容如下:

代码语言:javascript
复制
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")
            }
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41784581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档