小编Joc*_*rGG的帖子

我无法在 swift 2.3 中播放保存在目录路径和 AVPlayer 中的视频

我正在使用 录制视频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)

xcode ios swift swift2

0
推荐指数
1
解决办法
1430
查看次数

标签 统计

ios ×1

swift ×1

swift2 ×1

xcode ×1