我正在访问我的设备 photoLibrary 的视频。 Everythig工作得很好。现在我有一个视频网址,我想获取视频数据,以便我可以通过REST API上传到服务器,但无法获取视频数据。获得以下错误 -
Error Domain=NSCocoaErrorDomain Code=256 "The file “asset.MOV” couldn’t be opened." UserInfo={NSURL=assets-library://asset/asset.MOV?id=52C33235-2BFE-4FA4-AC8C-5E48DC566847&ext=MOV}
ImagePickerController代码如下 -
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
if let image = info[UIImagePickerControllerEditedImage] as? UIImage {// Get the Image
}
else if let videoURL1 = info["UIImagePickerControllerReferenceURL"] as? URL
{
self.videoURL = videoURL1
}
picker.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController)
{
picker.dismiss(animated: true, completion: nil)
}
获取数据的代码如下 -
do
{
let data = try Data(contentsOf: self.videoURL.absoluteURL, options: .alwaysMapped)
print(data)
}
catch
{
print(error)
}
do
{
let data = try Data(contentsOf: self.videoURL.absoluteURL)
}
catch
{
print(error)
}