簡體   English   中英

如何快速將錄像保存到文檔目錄?

[英]How to save video recording to documents directory with swift?

我已經編寫了這段代碼來錄制視頻,並且想將filePath保存到documents目錄,該怎么辦?

func startRecording() {
    var currentDateTime = NSDate()
    var formatter = NSDateFormatter()
    formatter.dateFormat = "MM-dd-yyyy, hh:mm:ss a"
    var recordingName = formatter.stringFromDate(currentDateTime) + ".mp4"
    var pathArray = [dirPath, recordingName]
    let filePath = NSURL.fileURLWithPathComponents(pathArray)

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
        videoRecorder = UIImagePickerController()
        videoRecorder.delegate = self
        videoRecorder.sourceType = UIImagePickerControllerSourceType.Camera
        videoRecorder.mediaTypes = [kUTTypeMovie]
        videoRecorder.videoMaximumDuration = 3600.0
        videoRecorder.startVideoCapture()
    }
}

我之前做過,您可以使用NSFileHandle做到這一點

NSFileHandle(forWritingToURL:filePath,錯誤:無)

這個對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM