2015-10-13 113 views
0

我從應用中獲取自定義專輯中的所有視頻,並且需要將這些視頻顯示到UICollectionView中。獲取有關專輯中視頻的詳細信息

我能得到的視頻到一個數組中,並顯示視頻的縮略圖..

我怎樣才能獲得的,例如視頻的詳細信息:視頻時長,記錄的日期等。 。

這是我從一個特定的專輯

assets = [NSMutableArray new]; 
_library = [ALAssetsLibrary new]; 

[_library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop){ 

    if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqual:@"Custom App Album"]) { 

     [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){ 
      [group setAssetsFilter:[ALAssetsFilter allVideos]]; 

      if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) { 
       NSLog(@"asset: %@", result); 

       [assets addObject:result]; 
      } 

      [_collectionView reloadData]; 

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

了視頻和我這是怎麼顯示縮略圖,

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    GalleryCell *galleryCell = (GalleryCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"GalleryCell" forIndexPath:indexPath]; 

    ALAsset *alasset = [assets objectAtIndex:indexPath.row]; 
    galleryCell.videoImageView.image = [UIImage imageWithCGImage:alasset.thumbnail]; 

    return galleryCell; 
} 

謝謝。

+0

以編程方式,你不能......你必須有web服務... ... –

回答

1

以下是React Native的代碼片段。您可以從結果和組中獲取詳細信息。

 CGSize dimensions = [result defaultRepresentation].dimensions; 
     CLLocation *loc = [result valueForProperty:ALAssetPropertyLocation]; 
     NSDate *date = [result valueForProperty:ALAssetPropertyDate]; 
     [assets addObject:@{ 
          @"node": @{ 
           @"type": [result valueForProperty:ALAssetPropertyType], 
           @"group_name": [group valueForProperty:ALAssetsGroupPropertyName], 
           @"image": @{ 
            @"uri": uri, 
            @"height": @(dimensions.height), 
            @"width": @(dimensions.width), 
            @"isStored": @YES, 
            }, 
           @"timestamp": @(date.timeIntervalSince1970), 
           @"location": loc ? 
           @{ 
           @"latitude": @(loc.coordinate.latitude), 
           @"longitude": @(loc.coordinate.longitude), 
           @"altitude": @(loc.altitude), 
           @"heading": @(loc.course), 
           @"speed": @(loc.speed), 
           } : @{}, 
           } 
          }]; 
相關問題