我正在使用 录制视频AVFoundation,并从视频创建了一个预览,当我完成录制视频时,视频正在预览中播放,但是当我使用以下方法保存视频时:
var fileName = "\(self.tField.text!).mp4"
fileName = fileName.stringByReplacingOccurrencesOfString(" ", withString: "_")
let path = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
//let originVideoFile = self.filePath
let destinationVideoFile = path.URLByAppendingPathComponent(fileName)
let data = NSData(contentsOfURL: self.filePath)
//try data!.writeToURL(destinationVideoFile!, options: [])
let fileManager = NSFileManager()
fileManager.createFileAtPath((destinationVideoFile?.path)!, contents: data, attributes: nil)
Run Code Online (Sandbox Code Playgroud)
视频文件已创建,但当我想重新播放视频时,我无权访问此文件,但相机胶卷可以播放视频。
要获得“ filePath”,我正在使用以下委托方法AVFoundation:
func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
print("capture did finish")
print(captureOutput);
print(outputFileURL);
self.filePath = outputFileURL
performSegueWithIdentifier("previewVideo", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, …Run Code Online (Sandbox Code Playgroud)