iphone - Copy downloaded video to camera roll -


even though looks simple procedure, it's 3 hours i'm trying without success. missing stupid.

so, have app downloading videos internet. videos correctly stored locally because can play them providing local url. but, can't succeed in copying videos camera roll. here do:

    alassetslibrary *library = [[alassetslibrary alloc] init];     alassetslibrarywritevideocompletionblock videowritecompletionblock =     ^(nsurl *newurl, nserror *error) {         if (error) {             nslog( @"error writing image metadata photo library: %@", error );         } else {             nslog( @"wrote image metadata photo library %@", newurl.absolutestring);         }     };      nslog(@"file %@", localpath);     nsurl *url = [nsurl fileurlwithpath:localpath isdirectory:no];     [library writevideoatpathtosavedphotosalbum:url                                 completionblock:videowritecompletionblock]; 

but output is:

2013-07-24 00:13:32.094 app[1716:907] file /var/mobile/applications/70c18c4e-9f97-4a6a-b63e-1bd19961f010/documents/downloaded_video.mp4 2013-07-24 00:13:32.374 app[1716:907] wrote image metadata photo library (null) 

and of course file not saved in camera roll. it's simple mp4, compatible device i'm using (i.e. should possible save it).

i have no idea do. hint highly appreciated. thanks

i may have found workaround you. have tried avassetexportsession?

in sample below, built simple app has 2 buttons on screen. 1 calls onsavebtn:, grabs url of video have in app's resource bundle , saves user's saved photos album. (though, in case videos return yes videoatpathiscompatiblewithsavedphotosalbum:. didn't have videos don't return otherwise.)

the second button wired onexportbtn:, takes video want save, creates avassetexportsession, exports video temp directory, , copies exported video saved photos album. due export time, method take longer simple copy, maybe alternate path - check results of videoatpathiscompatiblewithsavedphotosalbum:, , if yes, copy directly album. otherwise, export video, copy.

without having video file doesn't return no compatibility call, i'm not 100% sure work you, it's worth shot.

you may want check out question, explores video formats compatible on device may using.

#import <avfoundation/avfoundation.h> #import <assetslibrary/assetslibrary.h>  - (ibaction)onsavebtn:(id)sender {     nsurl *srcurl = [[nsbundle mainbundle] urlforresource:@"wp_20121214_001" withextension:@"mp4"];     [self savetocameraroll:srcurl]; }  - (ibaction)onexportbtn:(id)sender {     nsurl *srcurl = [[nsbundle mainbundle] urlforresource:@"wp_20121214_001" withextension:@"mp4"];     avasset *srcasset = [avasset assetwithurl:srcurl];      // create export session     avassetexportsession *exportsession = [[avassetexportsession alloc] initwithasset:srcasset presetname:avassetexportpresethighestquality];      // export file tmp dir     nsstring *filename = [srcurl lastpathcomponent];     nsstring *tmpdir = nstemporarydirectory();     nsurl *tmpurl = [nsurl fileurlwithpath:[tmpdir stringbyappendingpathcomponent:filename]];      exportsession.outputurl = tmpurl;     exportsession.outputfiletype = avfiletypequicktimemovie;      [exportsession exportasynchronouslywithcompletionhandler:^{                // copy tmp file camera roll         switch ([exportsession status]) {             case avassetexportsessionstatusfailed:                 nslog(@"export failed: %@", [[exportsession error] localizeddescription]);                 break;             case avassetexportsessionstatuscancelled:                 nslog(@"export canceled");                 break;             case avassetexportsessionstatuscompleted:                 nslog(@"export successful");                 [self savetocameraroll:exportsession.outputurl];                 break;             default:                 break;         }     }]; }  - (void) savetocameraroll:(nsurl *)srcurl {     nslog(@"srcurl: %@", srcurl);      alassetslibrary *library = [[alassetslibrary alloc] init];     alassetslibrarywritevideocompletionblock videowritecompletionblock =     ^(nsurl *newurl, nserror *error) {         if (error) {             nslog( @"error writing image metadata photo library: %@", error );         } else {             nslog( @"wrote image metadata photo library %@", newurl.absolutestring);         }     };      if ([library videoatpathiscompatiblewithsavedphotosalbum:srcurl])     {         [library writevideoatpathtosavedphotosalbum:srcurl                                     completionblock:videowritecompletionblock];     } } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -