ios - Objective-C: Getting PNG Thumbnail from Movie with NSData -


i have following code attempt screenshot of video file nsdata. can confirm nsdata valid , not nil, both datastring , movieurl returning nil.

- (uiimage *)imagefrommovie:(nsdata *)moviedata {      // set movie player     nsstring *datastring = [[nsstring alloc] initwithdata:moviedata encoding:nsutf8stringencoding];     nsurl *movieurl = [nsurl urlwithstring:datastring];      // thumbnail     avurlasset *asset1 = [[avurlasset alloc] initwithurl:movieurl options:nil];     avassetimagegenerator *generate1 = [[avassetimagegenerator alloc] initwithasset:asset1];     generate1.appliespreferredtracktransform = yes;     nserror *err = null;     cmtime time = cmtimemake(1, 2);     cgimageref oneref = [generate1 copycgimageattime:time actualtime:null error:&err];     uiimage *one = [[uiimage alloc] initwithcgimage:oneref];      return(one);  } 

edit: here's @ where/how i'm getting nsdata uiimagepicker

if ([mediatype isequaltostring:@"alassettypevideo"]) {      alassetslibrary *assetlibrary=[[alassetslibrary alloc] init];     [assetlibrary assetforurl:[[info objectatindex:x] valueforkey:uiimagepickercontrollerreferenceurl] resultblock:^(alasset *asset) {      alassetrepresentation *rep = [asset defaultrepresentation];          unsigned long datasize = (unsigned long)[rep size];     byte *buffer = (byte*)malloc(datasize);         nsuinteger buffered = [rep getbytes:buffer fromoffset:0.0 length:datasize error:nil];      //here’s nsdata     nsdata *data = [nsdata datawithbytesnocopy:buffer length:buffered freewhendone:yes];        } failureblock:^(nserror *err) {              nslog(@"error: %@",[err localizeddescription]);         }]; } 

possible, have problems encoding.

nsstring instance method -(id)initwithdata:data:encoding returns nil if data not represent valid data encoding.(https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/nsstring_class/#//apple_ref/occ/instm/nsstring/initwithdata:encoding:)

try use correct encoding in -(id)initwithdata:data:encoding method.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -