2013-12-16 79 views
0

我正在製作一個相機應用程序,我想要獲取用戶在其iPhone上創建的所有視頻。ALAssetsLibrary獲取所有視頻

目前我的代碼只能從用戶相機膠捲獲取視頻。我的一些用戶抱怨說,他們在其相冊應用程序下創建了多個自定義文件夾,並在那裏存儲了一些視頻。由於我的代碼僅查看相機膠捲,因此不會從其他文件夾中拾取電影。是否有可能我可以到他們的其他文件夾?

這是我到目前爲止。

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
    { 
     [group enumerateAssetsUsingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) 
     { 
       if (alAsset) 
       { 
        ALAssetRepresentation *representation =[alAsset defaultRepresentation]; 
        NSURL *url = [representation url]; 
        NSString *assetType=[alAsset valueForProperty:ALAssetPropertyType]; 


        //videos only 
        if ([assetType isEqualToString:@"ALAssetTypeVideo"]) 
        { 
        ..... 
+1

嘗試將此類assetsGroupType用作「ALAssetsGroupAll」。 – Bharath

回答

1

要獲得從iTunes同步的媒體,您需要使用ALAssetsGroupLibrary。 Here您可以找到ALAssetsGroupType的所有可能變體。因此,只要改變

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:... 

[library enumerateGroupsWithTypes:(ALAssetsGroupSavedPhotos | ALAssetsGroupLibrary) usingBlock:... 
+0

這沒有奏效 –

2

你得創造的資產中的過濾器,這樣的事情:

用於過濾
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) { 

    ALAssetsFilter *allVideosFilter = [ALAssetsFilter allVideos]; 
    [group setAssetsFilter:allVideosFilter]; 
    //... 
}; 

選項包括: - allAssets - allVideos - allPhotos

希望這有助於

0

這檢索所有視頻,包括任何用戶從iTunes同步:

// Enumerate just the photos and videos by using ALAssetsGroupSavedPhotos 

[library enumerateGroupsWithTypes:ALAssetsGroupAll | ALAssetsGroupLibrary 
         usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
{ 
    if (group != nil) 
    { 
     // Within the group enumeration block, filter to enumerate just videos. 
     [group setAssetsFilter:[ALAssetsFilter allVideos]]; 
     [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 
      if (result) { 
       // Do whatever you need to with `result` 
      } 
     }]; 
    } else { 
     // If group is nil, we're done enumerating 
     // e.g. if you're using a UICollectionView reload it here 
     [collectionView reloadData]; 
    } 
} failureBlock:^(NSError *error) { 
    // If the user denied the authorization request 
    NSLog(@"Authorization declined"); 
}]; 

注意ALAssetsGroupAll | ALAssetsGroupLibrary

根據docsALAssetsGroupAll「與將所有類型的組合在一起除了ALAssetsGroupLibrary」相同。因此我們還添加了ALAssetsGroupLibrary,其中「包含了所有從iTunes同步的資產」。

相關問題