用于音频的ALAssetsLibrary

时间:2012-10-16 14:26:00

标签: ios ios5 alassetslibrary alasset

我试图通过这段代码使用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");
 }];

但是,这只会加载视频和图片,而不会加载音频文件。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

关于Apple.Developer ALAsset documentaion ALAsset 对象代表由Photo应用程序管理的照片或视频

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

所以我认为,ALAssetsLibrary不会检索你需要的东西:)