Search code examples
objective-cphphotolibrary

I am using PH photo library to get all the photos and videos


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 ?


Solution

  • 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.