Featured post
iphone - Save Video to iPad Videos app -
i have been trying use uisavevideoatpathtosavedphotosalbum
save video (stored locally within application). when try save it, error saying "operation failed because video file invalid , cannot played." file minute long , .mp4 file. don't have problem playing mpmovieplayer, won't save. here code:
nsstring *path = [[nsbundle mainbundle] pathforresource:@"videofile" oftype:@"mp4"]; uisavevideoatpathtosavedphotosalbum(path, self, @selector(status:didfinishsavingwitherror:contextinfo), nil);
is method not designed work ipad? says "savedphotosalbum". mean have go through photos app view it, or name of method , in videos app? if me work out, appreciate it.
it should work long uivideoatpathiscompatiblewithsavedphotosalbum() returns true. however, i've had issue before , seemed have better luck creating , alassetslibrary object , using method:
- (void)writevideoatpathtosavedphotosalbum:(nsurl *)videopathurl completionblock:(alassetslibrarywritevideocompletionblock)completionblock
i didn't try edit generic or 100% portable. grabbed code wrote saving videos give starting point using alassetlibrary instead:
- (void) savevideofile:(nsstring *)fullpathvideofile completiontarget:(id)thecompletiontarget action:(sel)thecompletionaction context:(id)thecontext { writefailed = no; completiontarget = thecompletiontarget; completionaction = thecompletionaction; completioncontext = thecontext; // alassetslibrarywritevideocompletionblock // void (^completionblock)(nsurl *, nserror *) = ^(nsurl *asseturl, nserror *error) { if ( error != nil ) { writefailed = yes; } writingtolibrary = no; [self notifycompletiontarget]; }; // clean previous calls // if ( asseturl != nil ) { [asseturl release]; asseturl = nil; } if ( assetfullpathname != nil ) { [assetfullpathname release]; assetfullpathname = nil; } writingtolibrary = yes; // make sure have file // if ( [[nsfilemanager defaultmanager] fileexistsatpath:fullpathvideofile] == no) { writingtolibrary = no; writefailed = yes; [self notifycompletiontarget]; return; } // set asseturl sending library // assetfullpathname = [[nsmutablestring alloc] initwithcapacity:(nsuinteger)1024]; [assetfullpathname setstring:fullpathvideofile]; asseturl = [[nsurl alloc] initfileurlwithpath:assetfullpathname isdirectory:no]; // use possible alternative method if method doesn't want work // if ( [library videoatpathiscompatiblewithsavedphotosalbum:asseturl]==no ) { if ( uivideoatpathiscompatiblewithsavedphotosalbum( assetfullpathname ) ) { uisavevideoatpathtosavedphotosalbum( assetfullpathname, self, @selector(video:didfinishsavingwitherror:contextinfo:), nil ); } else { writingtolibrary = no; writefailed = yes; [self notifycompletiontarget]; } return; } // write video library // [library writevideoatpathtosavedphotosalbum:asseturl completionblock:completionblock]; }
- Get link
- X
- Other Apps
Comments
Post a Comment