2014-09-03 132 views
-1

如何使用我的自定義相冊保存視頻。 我找到了一個鏈接,但它不起作用Custom file manager將視頻保存到自定義相冊中iOS

它給出的url值爲空。

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

給出任何暗示此..

+0

檢查此鏈接http://stackoverflow.com/questions/17569505/saving-video-in-an-album-created,並檢查此鏈接http://stackoverflow.com/questions/10610708/ios-create- custom-photo-album-in-photos-addassetsgroupalbumwithname-under-ios-5 – 2014-09-04 12:07:07

+0

我檢查這兩個鏈接超過10次,但我沒有找到任何東西。我將郵件發送到您的郵件ID。 – 2014-09-04 12:09:23

+0

檢查並讓你知道。 – 2014-09-04 12:13:04

回答

1

您可以使用此鏈接保存視頻.. GitHub Link

將這兩個文件導入到您的項目中。

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

然後在您保存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是你的視頻電影,如果你有網址,然後保存它的URL名稱。 是在.h文件中定義的ALAssetLibrary albumName是你的相冊名稱你想要什麼..我希望這會幫助你。

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. ALAssetsLibrary創建一個對象,並寫了塊保存在自定義的相冊視頻文件,就這樣,
[ALAssetsLibraryObject addAssetURL:clipURl toAlbum:AlbumName withCompletionBlock:^(NSError *error) 
{ 
    if (error!=nil) { 
     NSLog(@"Big error: %@", [error description]) 
    } 
}];