0

我正在尝试通过这段代码使用 ALAssetLibrary 在我的应用程序中加载所有文件(音频、视频和图像):

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    // Within the group enumeration block, filter to enumerate everything.
    [group setAssetsFilter:[ALAssetsFilter allAssets]];
    // Accessing all the assets.

    for (int i = 0;i<[group numberOfAssets] ; i++) {

    [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:i] options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
        // The end of the enumeration is signaled by asset == nil
        if (alAsset) {
            ALAssetRepresentation *representation = [alAsset defaultRepresentation];
            NSURL *url = [representation url];
            NSLog(@"%@",url);
            AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];

            //Doing some stuff with assets

                       }
    }]; 
    }
}
failureBlock: ^(NSError *error) {
   NSLog(@"No groups");
 }];

但是,这只会加载视频和图像,而不是音频文件。我怎样才能做到这一点?

4

1 回答 1

1

关于Apple.Developer ALAsset 文档,一个ALAsset对象表示由 Photo 应用程序管理的照片或视频。

资产可以有多种表现形式,例如以 RAW 和 JPG 拍摄的照片。同一资产的不同表示可能具有不同的维度。

所以我认为,ALAssetsLibrary 不会检索您需要的内容:)

于 2012-12-04T04:26:35.123 回答