在创建的相册中保存视频 [英] Saving Video in an Album Created

查看:172
本文介绍了在创建的相册中保存视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppDelegate方法中使用此代码创建了一个专辑

i have created an album using this code in AppDelegate methode

NSString *albumName=@"999Videos";
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library addAssetsGroupAlbumWithName:albumName
                         resultBlock:^(ALAssetsGroup *group) {
                             NSLog(@"added album:%@", albumName);
                         }
                        failureBlock:^(NSError *error) {
                            NSLog(@"error adding album");
                        }];

现在我想将录制的视频保存到这个创建的999Videos专辑中。不是我拥有的photosAlbum这样做。

Now i want to save the recorded videos to this 999Videos album created.Not to the photosAlbum which i have done like this.

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

视频正在保存但不在999Videos相册中。有人可以告诉我如何将视频保存到我的自定义相册中?

The videos are saving but not in the 999Videos album.Could someone please tell me how can i save the videos to my custom album?

推荐答案

在撕掉我的头发后,我终于找到了解决方案。这是我的代码。

After tearing my hair out over this finally i found the solution.Here is my code.

NSString *albumName=@"999 Videos";
                ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
                [library addAssetsGroupAlbumWithName:albumName
                                         resultBlock:^(ALAssetsGroup *group) {
                                             NSLog(@"added album:%@", albumName);
                                            }
                                        failureBlock:^(NSError *error) {
                                            NSLog(@"error adding album");

                                        }];

__block ALAssetsGroup* groupToAddTo;
    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                                    usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                                            if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:albumName]) {
                                                    NSLog(@"found album %@", albumName);
                                                    groupToAddTo = group;
                                                }
                                            }
                                          failureBlock:^(NSError* error) {
                                              NSLog(@"failed to enumerate albums:\nError: %@", [error localizedDescription]);
                                          }];


                [library assetForURL:assetURL
                              resultBlock:^(ALAsset *asset) {
                                  // assign the photo to the album
                                  [groupToAddTo addAsset:asset];
                                  NSLog(@"Added %@ to %@", [[asset defaultRepresentation] filename], albumName);
                              }
                             failureBlock:^(NSError* error) {
                                 NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
                             }];

这篇关于在创建的相册中保存视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆