将视频保存到自定义相册iOS

时间:2014-09-03 13:34:06

标签: objective-c ios7 ios6 alassetslibrary alasset

如何使用自定义相册保存视频。 我找到了一个链接,但它不起作用Custom file manager

它给出了url值为null。

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

对此提出任何建议..

2 个答案:

答案 0 :(得分: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)
     {

     }];

}

}

你可以尝试一下。这对你有所帮助。只需浏览“http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/”链接并下载示例项目即可。

  
      
  1. 将两个文件"ALAssetsLibrary+CustomPhotoAlbum.h""ALAssetsLibrary+CustomPhotoAlbum.m"拖放到您的项目中,然后添加"AssetsLibrary.framework"。现在您已准备好进行编码。只需继续ViewController.h班级并导入<AssetsLibrary/AssetsLibrary.h>"ALAssetsLibrary+CustomPhotoAlbum.h"文件。
  2.   
  3. ALAssetsLibrary创建一个对象并编写一个块,用于将视频文件保存在自定义相册中,就像这样,
  4.   
[ALAssetsLibraryObject addAssetURL:clipURl toAlbum:AlbumName withCompletionBlock:^(NSError *error)
{   
    if (error!=nil) {
        NSLog(@"Big error: %@", [error description])
    } 
}];

答案 1 :(得分:1)

您可以使用此链接保存视频.. GitHub Link

将这两个文件导入您的项目。

  1. ALAssetsLibrary + CustomPhotoAlbum.h
  2. ALAssetsLibrary + CustomPhotoAlbum.m
  3. 然后在你的保存IBAction方法中写下这行......

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

    其中.. outputfilepath 是您的视频,如果您有网址,请使用网址名称保存。 是在.h文件中定义的ALAssetLibrary albumName 是您的相册名称您想要什么..我希望这会对您有所帮助。

相关问题