简体   繁体   English

如何使用ALAssets库获取视频的绝对路径?

[英]How to get Absolute path for a video using ALAssets Library?

Its simple, How can i get an absolute path for a video retrieved using ALAssets Library? 它很简单,如何获得使用ALAssets库检索的视频的绝对路径? I want to upload this video as file attachment using ASI framework. 我想使用ASI框架将此视频作为文件附件上传。

It works if i use UIImagePickerViewController. 如果我使用UIImagePickerViewController,它可以工作。 But thats NOT an option any more. 但这不是一个选择。 I also dont want to use NSData or copy-pasting video to temp file. 我也不想使用NSData或将粘贴视频复制到临时文件。 Need a smart solution? 需要聪明的解决方案? Anybody ? 有人吗

You can't get the absolute path (file system path) for a video you retrieved using the AssetsLibrary-Framework. 您无法获取使用AssetsLibrary-Framework检索的视频的绝对路径(文件系统路径)。 The simple reason for that is that these files are outside your app's sandbox and you can't access them directly. 这样做的简单原因是这些文件不在应用程序的沙箱中,因此您无法直接访问它们。 You need to use the getBytes-Method of ALAssetsRepresentation to get the byte data of the video file. 您需要使用ALAssetsRepresentation的getBytes-Method来获取视频文件的字节数据。 Most likely you will have to save this data to a temp file, before you can attach it to an email. 在将数据附加到电子邮件之前,最有可能必须将这些数据保存到临时文件中。

Cheers, 干杯,

Hendrik 亨德里克

You can use ALAssetPropertyAssetURL . 您可以使用ALAssetPropertyAssetURL From documentation : 文档

  • The key to retrieve a URL identifier for the asset. 检索资产的URL标识符的键。

  • The corresponding value is an NSURL object. 相应的值是一个NSURL对象。

  • This URL is used by the library-change notifications to identify assets and asset groups. 库更改通知使用此URL来标识资产和资产组。 Only the ALAssetRepresentation and ALAssetsGroup classes support this property. 仅ALAssetRepresentation和ALAssetsGroup类支持此属性。

So, once you get ALAsset object you can get url like this: 因此,一旦获得ALAsset对象,您就可以像这样获得网址:

 asset.defaultRepresentation.url

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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