Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

iphone - Get video NSData from ALAsset url iOS

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

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

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

I also tried something like this

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

The url that I get from the ALAsset:-

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.

Getting video from ALAsset

Any hint in right direction would be highly appreciated.

Waiting for your replies

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...