使用 AssetsLibrary 框架 iPhone 访问库中的视频?

发布于 2024-09-27 09:30:39 字数 1168 浏览 7 评论 0原文

我正在尝试在以下代码的帮助下使用 AssetsLibrary Framework 访问 iPhone 库中的视频...但是当我运行应用程序时,代码不起作用...数组资产仍然为空?我做错了什么?

顺便说一句,我的 iPhone 是 3G 升级到 iPhone 4.1。(但资产框架没有给出任何错误)

NSMutableArray *assets = [[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];

void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != NULL) {
                NSLog(@"See Asset: %@", result);
                [assets addObject:result];
            }
        };

    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
        if(group != nil) {NSLog(@"dont See Asset: ");
                [group enumerateAssetsUsingBlock:assetEnumerator];
            }
        };

    assets = [[NSMutableArray alloc] init];
    library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                           usingBlock:assetGroupEnumerator
                         failureBlock: ^(NSError *error) {
                                 NSLog(@"Failure");
                             }];

I am trying to access videos in iPhone library using AssetsLibrary Framework with the help of following code...but when I run the application the code is not working...the array assets is still empty? What am I doing wrong?

by the way my iPhone is a 3G upgraded to iPhone 4.1.(but assets framework is not giving any error)

NSMutableArray *assets = [[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];

void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != NULL) {
                NSLog(@"See Asset: %@", result);
                [assets addObject:result];
            }
        };

    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
        if(group != nil) {NSLog(@"dont See Asset: ");
                [group enumerateAssetsUsingBlock:assetEnumerator];
            }
        };

    assets = [[NSMutableArray alloc] init];
    library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                           usingBlock:assetGroupEnumerator
                         failureBlock: ^(NSError *error) {
                                 NSLog(@"Failure");
                             }];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绝情姑娘 2024-10-04 09:30:40

双重初始化:

 NSMutableArray *assets = [[NSMutableArray alloc]init];
 ALAssetsLibrary *library =[[ALAssetsLibrary alloc]init];

 void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
 if(result != NULL) {
      NSLog(@"See Asset: %@", result);
      [assets addObject:result];

        }
};

void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
    if(group != nil) {NSLog(@"dont See Asset: ");
            [group enumerateAssetsUsingBlock:assetEnumerator];
    }
};

   assets = [[NSMutableArray alloc] init];
   library = [[ALAssetsLibrary alloc] init**];
   [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                       usingBlock:assetGroupEnumerator
                     failureBlock: ^(NSError *error) {
                             NSLog(@"Failure");
                         }];

Double Init:

 NSMutableArray *assets = [[NSMutableArray alloc]init];
 ALAssetsLibrary *library =[[ALAssetsLibrary alloc]init];

 void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
 if(result != NULL) {
      NSLog(@"See Asset: %@", result);
      [assets addObject:result];

        }
};

void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
    if(group != nil) {NSLog(@"dont See Asset: ");
            [group enumerateAssetsUsingBlock:assetEnumerator];
    }
};

   assets = [[NSMutableArray alloc] init];
   library = [[ALAssetsLibrary alloc] init**];
   [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                       usingBlock:assetGroupEnumerator
                     failureBlock: ^(NSError *error) {
                             NSLog(@"Failure");
                         }];
独夜无伴 2024-10-04 09:30:40

我正在使用 ELC 图像选择器控制器,它已经在使用 ALAssetsGroupAll,但仍然没有显示任何视频。

我通过添加资产过滤器解决了这个问题。您可以限制为视频、照片或两者。我猜只有照片是默认设置。如果上述失败,请考虑以下行:

[assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];

I am using ELC Image Picker Controller, and it's already using ALAssetsGroupAll and still not showing any videos.

I solved this by adding an asset filter. You can limit to videos, photos or both. I guess photos-only was the default. Please consider the following line if the above fails:

[assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];
入画浅相思 2024-10-04 09:30:39

4.1 升级似乎“破坏”了一些图像选择器示例,请观察以下几行,这些行在您发布的代码之后运行:

NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces;
[assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];

这在我的 4.1 iPhone 和模拟器上都提供了零资产。然而,更改 groupTypes 会有所帮助,因此设置

 NSUInteger groupTypes = ALAssetsGroupAll;

后您应该会开始看到一些资产。

the 4.1 upgrade seems to have 'broken' some of the image picker examples, observe the following lines, which run after the code you have posted:

NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces;
[assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];

This gives zero assets both on my 4.1 iPhone and simulator. However changing the groupTypes helps, so set

 NSUInteger groupTypes = ALAssetsGroupAll;

and you should start seeing some assets.

情独悲 2024-10-04 09:30:39

我在 Xcode 4.1、IOS 5 中执行此操作:

ALAssetsGroupEnumerationResultsBlock assetEnumerator = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
    if(result != NULL) {
        NSLog(@"See Asset: %@", result);
        [assets addObject:result];
    }
};

ALAssetsLibraryGroupsEnumerationResultsBlock assetGroupEnumerator = ^(ALAssetsGroup *group, BOOL *stop) {
    if(group != nil) {NSLog(@"dont See Asset: ");
        [group enumerateAssetsUsingBlock:assetEnumerator];
    }
};

assets = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                       usingBlock:assetGroupEnumerator
                     failureBlock: ^(NSError *error) {
                         NSLog(@"Failure");
                     }];

它对我有用。

I did this in Xcode 4.1, IOS 5:

ALAssetsGroupEnumerationResultsBlock assetEnumerator = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
    if(result != NULL) {
        NSLog(@"See Asset: %@", result);
        [assets addObject:result];
    }
};

ALAssetsLibraryGroupsEnumerationResultsBlock assetGroupEnumerator = ^(ALAssetsGroup *group, BOOL *stop) {
    if(group != nil) {NSLog(@"dont See Asset: ");
        [group enumerateAssetsUsingBlock:assetEnumerator];
    }
};

assets = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                       usingBlock:assetGroupEnumerator
                     failureBlock: ^(NSError *error) {
                         NSLog(@"Failure");
                     }];

It worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文