0

i have created a album in my photo library using this code

NSString *albumName=@"iphonemaclover";
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library addAssetsGroupAlbumWithName:albumName
                             resultBlock:^(ALAssetsGroup *group) {
                                 NSLog(@"added album:%@", albumName);

AND I have download the video from server using this code

-(IBAction)btnDownload:(UIView *)sender {


    [DSBezelActivityView newActivityViewForView:self.view withLabel:@"DOWNLOADING..."];

    NSString *albumName=@"album name";



                                 NSURL *url = [NSURL URLWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];





                                 ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];



                                 [request setDelegate:self];
                                 [request setDownloadDestinationPath:@"/Users/seemtech/Desktop/dd/vvv.m4v"];//work fine 
                                 [ASIHTTPRequest setDefaultTimeOutSeconds:3000];

                                 [request startAsynchronous];



                             }
                            failureBlock:^(NSError *error) {
                                NSLog(@"error adding album");
                            }];


            }

    -(void)requestFinished:(ASIHTTPRequest *)request

    {

    [[[[UIAlertView alloc] initWithTitle:@"Message"
                                 message:@"Success!!!"
                                delegate:self
                       cancelButtonTitle:@"OK"
                       otherButtonTitles:nil] autorelease] show]; [DSBezelActivityView removeViewAnimated:YES];


    }

    -(void)requestFailed:(ASIHTTPRequest *)request {

    NSLog(@"error==%@",request.error); [DSBezelActivityView removeViewAnimated:YES];

    }

I need to save the video in the album i created. How can i do that?

9to5ios
  • 5,319
  • 2
  • 37
  • 65

1 Answers1

2

You can save your video to your saved photos album using "ALAssetsLibrary" like this:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSURL *capturedVideoURL = [NSURL URLWithString:@"/Users/seemtech/Desktop/dd/vvv.m4v"];

if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:capturedVideoURL]) {
    // request to save video in photo roll.
    [library writeVideoAtPathToSavedPhotosAlbum:capturedVideoURL completionBlock:^(NSURL *assetURL, NSError *error) {
        if (error) {
            NSLog(@"error while saving video");
        } else{
            [self addAssetURL:assetURL toAlbum:@"iphonemaclover"];
        }
    }];
}

Add that asset to your album

- (void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)albumName
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {
            //If album found
            [library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
            //add asset to album
                [group addAsset:asset];
            } failureBlock:nil];
        }
        else {
            //if album not found create an album
            [library addAssetsGroupAlbumWithName:albumName resultBlock:^(ALAssetsGroup *group)     {
                [self addAssetURL:assetURL toAlbum:albumName];
            } failureBlock:nil];
        }
    } failureBlock: nil];
}

The only problem with this code is it keeps a copy of video in saved photos album. So find a way to delete an asset from albums. This Link might help.

Community
  • 1
  • 1
RoHaN
  • 372
  • 3
  • 14