Pergunta

I tried to use the following code to load a movie from the "Camera Roll" folder, but I don't know which URL I should give.

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

How can I find the filename of a movie in my photo album?

Foi útil?

Solução

If you want to access the assets in the camera roll directly you could use the assets library framework. The following code should log the path to each movie in the camera roll:

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
}];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top