ios - 使用带有来自设备的 avfoundation 的 swift 将 Capture session 保存在文档目录中

标签 ios swift video avfoundation

下面的片段我用来将视频保存在文档目录中(从 AVCaptureMoviefileOutput 收到的 NSdata)

func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
    delegate?.recordingStopped?()

   var data = NSData(contentsOfURL: outputFileURL)
    let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
    let documentsDirectory:AnyObject=paths[0]
    let dataPath=documentsDirectory.stringByAppendingPathComponent("/MyFolder")
    if (!NSFileManager.defaultManager().fileExistsAtPath(dataPath)) {
        NSFileManager.defaultManager() .createDirectoryAtPath(dataPath as String, withIntermediateDirectories: false, attributes: nil, error: nil)
    }

    var outputPathr = "\(dataPath)/TestproximityRwqxq.mp4"

    var success = data!.writeToFile(outputPathr as String, options: nil, error: nil)

}

如果用于其他视频(从 NSbundle 中选择视频并转换为 NSdata),相同的代码在模拟器中工作,但不适用于设备,请帮助

最佳答案

此代码运行良好,我们需要使用最低 iOS 版本 8.4(XCode 6.4) 的设备。版本低于 8.4 的设备无法使用 Swift2 获取文档目录的内容。

关于ios - 使用带有来自设备的 avfoundation 的 swift 将 Capture session 保存在文档目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31936811/

相关文章:

ios - 在 Swift 中使用 C API

iphone - XCode : Using the command line tools, 如何从文件夹创建 git 并将其导入项目

ios - 如何在不关闭并重新加载应用程序的情况下获取新的 JSON 响应

c# - 在线程中创建 DirectShow 图形

video - 根据ffmpeg视频动态调整jwplayer大小

ios - 小屏幕开发

ios - 请求接收推送操作的权限

swift - 阿拉莫菲尔 4 请求开放天气

python - 在 GAE 上使用 Python 将 .ts 文件从 m3u8 合并到单个 mp4(无 ffmpeg)

ios - 剃掉 UIImageView 的一侧?