简体   繁体   中英

Swift AVCaptureMovieFileOutput can't find URL

Currently I am trying to use an AVCaptureMovieFileOutput to record video and save it to the photo library. However, once the URL of the photo library is passed to the startRecording function, it claims that "The requested URL was not found on this server." What is the proper way to create the URL so that the startRecording function can recognize it?

Here is how I initialize the URL:

paths = try FileManager.default.url(for: .picturesDirectory, in:.userDomainMask, appropriateFor: nil, create: false)
movieURL = try paths.appendingPathComponent("output.mov")

This is the function where movieURL is passed to startRecording:

func recordVideo(_sender: AnyObject?){
    videoOutput.startRecording(toOutputFileURL: movieURL, recordingDelegate:     mself)

    let delayTime =  5.0
    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+delayTime){
        print("stopping")
        self.videoOutput.stopRecording()
    }
}

This is the error message:

Finished Optional(Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo={NSLocalizedDescription=The requested URL was not found on this server., NSUnderlyingError=0x15e88cc0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}, AVErrorRecordingSuccessfullyFinishedKey=false}) xtopping

Any help would be greatly appreciated.

You are trying to save it at the wrong directory. You can save it at the documentDirectory. For more information on where you can save your App documents you can read the Apple developer documents about File System Basics .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM