问题
I'm using Glimpse to record the contents of a UIView so it can save it to a file in the documents directory. I'm having trouble specifying a URL for the file output in the g.startRecording line in viewDidLoad. I'd like to have the return value from getDocumentsDirectory()
set as the URL but placing the method name as the parameter does not work. I have also tried to use documentsDirectory
and this does not work either and results in "Ambiguous use of 'startRecording" I am using Swift here is my code:
import UIKit
class ViewController: UIViewController, VLCMediaPlayerDelegate {
@IBOutlet weak var videoView: UIView!
var player: VLCMediaPlayer = VLCMediaPlayer()
let g: Glimpse = Glimpse()
let url = URL(string: "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let media = VLCMedia(url: url!)
player.media = media
player.delegate = self
player.drawable = videoView
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = paths[0]
player.play()
g.startRecording(videoView) { (documentsDirectory) in
<#code#>
}
}
func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = paths[0]
return documentsDirectory
}
@IBAction func stopButtonPressed(_ sender: UIButton) {
player.stop()
recorder.stop()
}
}
回答1:
You are using urls[0]
when you should just use .url
instead. Example:
func write(_ data: Data, to filename: String) throws {
let documentDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:false)
let fileURL = documentDirectory.appendingPathComponent(filename)
try data.write(to: fileURL)
}
来源:https://stackoverflow.com/questions/55570539/specifying-documents-directory-as-file-output-url-while-working-with-glimpse-in