2

i am saving all photos to uicollectionview. but it is saving in uiimageview. i need to show a play button when the file is video type. is there any way to find the type of the media while fetching ?

Lal Castro
  • 23
  • 4

2 Answers2

2

You can use PHFetchResult to get all PHAsset,change PHAssetMediaType you can get different result.

Here are get all videos sample codes:

PHFetchResult *results = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:nil];
NSMutableArray *temp = [NSMutableArray arrayWithCapacity:results.count];

[results enumerateObjectsUsingBlock:^(PHAsset *obj, NSUInteger idx, BOOL * _Nonnull stop) {
    [temp addObject:obj];
}];
Heisenbean
  • 61
  • 6
1

EveryPHAsset has a property mediaType which is PHAssetMediaType. It shows what type it is: Image, Video, Audio or eventually Unknown. There is also a mediaSubtypes property for some more specific info about the asset (high frame rate video, time-lapse video and so on).

So basically when you spread out the results in your collection view you display an image as a thumbnail but when you check the mediaType and you see it's a video you can decide how to deal with it - either prepare a player or present an other view/view controller to play that video.

Hope it helps for a start as I don't know how you've structured your fetching from the Photos library.

kacho
  • 371
  • 2
  • 14
  • Similar question with a LARGE BOUNTY http://stackoverflow.com/questions/43791151/100-bounty-actually-get-the-filename-of-image-saved-to-photos-album-2017-ios10 – Fattie May 10 '17 at 11:07