Save Video into Custom Album iOS

我只是一个虾纸丫 提交于 2019-12-10 12:25:04

问题


How to save video with my custom album . I found one link but it don't work Custom file manager

It gives the url value is null.

[VideoAlbumManager addVideoWithAssetURL:outputFileUrl toAlbumWithName:@"Video Maker"];//outputfileurl is my video url from document directory

Give any suggestion for this..


回答1:


You can use this link to save the video.. GitHub Link

Import this two files into your project.

  1. ALAssetsLibrary+CustomPhotoAlbum.h
  2. ALAssetsLibrary+CustomPhotoAlbum.m

Then in your save IBAction method write this lines..

if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(outputFilePath)){

    NSURL *muyrl=[NSURL fileURLWithPath:outputFilePath];
    [library saveVideo:muyrl toAlbum:albumName withCompletionBlock:^(NSError *error)
    {
        if (error!=nil) {
            NSLog(@"Big error: %@", [error description]);
        } 
    }];

Where.. outputfilepath is your videopath and if you have url then save it with URL name. library is ALAssetLibrary that define in .h file albumName is your Album name what do you want..I hope this will help you.




回答2:


-(void)SaveToalbum{
NSString *finalFileName=[NSString stringWithFormat:@"Documents/video.mov"];
NSString *videoOutputPath = [NSHomeDirectory()
                             stringByAppendingPathComponent:finalFileName];

NSString* webStringURL = [videoOutputPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url =[NSURL URLWithString:webStringURL];

ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:url])
{
    NSURL *clipURl = url;
    [library writeVideoAtPathToSavedPhotosAlbum:clipURl completionBlock:^(NSURL *assetURL, NSError *error)
     {

     }];

}

}

You can try with it. It will be helpful for you. Just go through "http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/" link and download the sample project.

  1. Drag-drop two file "ALAssetsLibrary+CustomPhotoAlbum.h" and "ALAssetsLibrary+CustomPhotoAlbum.m" into your project and add "AssetsLibrary.framework". Now you are ready for coding.Just go on your ViewController.h Class and import the <AssetsLibrary/AssetsLibrary.h> and "ALAssetsLibrary+CustomPhotoAlbum.h" file.
  2. Create a object for ALAssetsLibrary and write a block for saving the video file in custom album,just like this,
[ALAssetsLibraryObject addAssetURL:clipURl toAlbum:AlbumName withCompletionBlock:^(NSError *error)
{   
    if (error!=nil) {
        NSLog(@"Big error: %@", [error description])
    } 
}];


来源:https://stackoverflow.com/questions/25645793/save-video-into-custom-album-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!