iphone - How to save video from assets url -


i want save video app document asset url. asset url follows:-

"assets-library://asset/asset.mov?id=1000000394&ext=mov" 

i tried this:-

nsstring *str=@"assets-library://asset/asset.mov?id=1000000394&ext=mov"; nsdata *videodata = [nsdata datawithcontentsofurl:[nsurl urlwithstring:str]]; [videodata writetofile:mypath atomically:yes]; 

but on second line [nsdata datawithcontentsofurl:[nsurl urlwithstring:str]] got program crash reason:- terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[nsurl length]: unrecognized selector sent instance

i want know how access asset video url.

thanx help.

i think best bet use method

getbytes:fromoffset:length:error: 

of

alassetrepresentation 

you can default representation of asset so

alassetrepresentation *representation = [somevideoasset defaultrepresentation]; 

so off top of head should go (i'm away mac hasn't been tested)

alassetslibrary *assetlibrary=[[alassetslibrary alloc] init]; [assetlibrary assetforurl:videourl resultblock:^(alasset *asset) {     alassetrepresentation *rep = [asset defaultrepresentation];     byte *buffer = (byte*)malloc(rep.size);     nsuinteger buffered = [rep getbytes:buffer fromoffset:0.0 length:rep.size error:nil];     nsdata *data = [nsdata datawithbytesnocopy:buffer length:buffered freewhendone:yes];     [data writetofile:filepath atomically:yes]; } errorblock:^(nserror *err) {     nslog(@"error: %@",[err localizeddescription]); }]; 

where videourl asset url of video you're trying copy, , filepath path you're trying save to.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -