如何使用GPUImage在相机胶卷中加载预先录制的电影?

时间:2014-02-17 02:24:34

标签: ios alassetslibrary gpuimage

我尝试使用以下代码从“Camera Roll”文件夹加载电影,但我不知道应该给哪个网址。

NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"filename" withExtension:@"mp4"];
movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];

如何在相册中找到电影的文件名?

1 个答案:

答案 0 :(得分:0)

如果您想直接访问相机胶卷中的资源,可以使用assets library framework。以下代码应记录相机胶卷中每部电影的路径:

ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
ALAssetsGroupType assetTypes = ALAssetsGroupSavedPhotos | ALAssetsGroupAlbum | ALAssetsGroupLibrary | ALAssetsGroupPhotoStream;
NSMutableArray *assetGroups = [NSMutableArray array];

[assetsLibrary enumerateGroupsWithTypes:assetTypes usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
    // store the asset groups in an array
    if (group)
    {
        [assetGroups addObject:group];
    }
    // once all the groups are stored we can access the individual assets
    else
    {
        for (ALAssetsGroup *assetGroup in assetGroups)
        {
            [assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
            {
                if (result && [[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo])
                {
                    NSURL *assetURL = [[result defaultRepresentation] url];
                    NSLog(@"%@", [assetURL path]);
                }
            }];
        }
    }
}
failureBlock:^(NSError *error)
{
    // handle error
}];