本文介绍了从ALAsset url iOS获取视频NSData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法从从ALAsset获取的URL中检索NSData
I am not able to retrieve NSData from the url that I get from ALAsset
下面是我试过的代码: - 我总是得到NSData为nil。 p>
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.
非常感谢任何向正确方向的提示。
Any hint in right direction would be highly appreciated.
等待您的回复
推荐答案
请尝试以下代码: -
try this code:-
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!