从 ALAsset url iOS 获取视频 NSData [英] Get video NSData from ALAsset url iOS

查看:58
本文介绍了从 ALAsset url iOS 获取视频 NSData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从从 ALAsset 获得的 url 中检索 NSData

I am not able to retrieve NSData from the url that I get from ALAsset

以下是我尝试过的代码:- 我总是将 NSData 设为 nil.

Below is the code I tried:- I always get NSData as nil.

 NSData *webData = [NSData dataWithContentsOfURL:[asset defaultRepresentation].url];

我也试过这样的

 NSData *webData1 = [NSData dataWithContentsOfURL:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]]];

我从 ALAsset 得到的网址:-

The url that I get from the ALAsset:-

assets-library://asset/asset.MOV?id=1000000116&ext=MOV

assets-library://asset/asset.MOV?id=1000000116&ext=MOV

我已经在下面的链接中尝试过这个链接,但我需要不必要地写入一个非常耗时的临时位置.

I have tried this below link which works but I need to unnecessary write to a temp location which is very time consuming.

从 ALAsset 获取视频

任何有关正确方向的提示将不胜感激.

Any hint in right direction would be highly appreciated.

等待您的回复

推荐答案

试试这个代码:-

ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc((NSUInteger)rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:(NSUInteger)rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];

这篇关于从 ALAsset url iOS 获取视频 NSData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆