2013-06-19 91 views
3

我正在處理應用程序,在該應用程序中獲取存儲在庫中的視頻和圖像的資產url。 我想動態地知道url包含圖像或視頻。如何知道ALAsset網址是否包含視頻或圖片?

ALAsset對象具有DefaultAssetRepresentation屬性是可能的,該屬性返回資產對象的元數據,其中包含從庫中獲取的圖像或視頻。

但我已經有資產網址,我不想使用ALAsset。

因此,任何人都知道如何檢查資產url是否包含圖片或視頻? 我在很多地方搜索,但沒有得到任何東西。請幫我理清這個問題。

在此先感謝!

回答

30

http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAsset_Class/Reference/Reference.html#//apple_ref/occ/instm/ALAsset/valueForProperty

我認爲最好的辦法是

if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) { 
    // asset is a video 
} 

http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAsset_Class/Reference/Reference.html#//apple_ref/doc/constant_group/Asset_Types

資產類型

常量指定資產的類型。

NSString *const ALAssetTypePhoto; 
NSString *const ALAssetTypeVideo; 
NSString *const ALAssetTypeUnknown; 
相關問題