6

Is there any way I can check if a mediaItem fetched from iPhone's music library represents a iCloud Item?

I know MPMediaItemPropertyAssetURL property of a media Item is nil for both DRM Protected media as well as for iCloud item, but I have no idea how to determine if the item is DRM protected or it is available on cloud.

Thanks in advance

Manish Ahuja
  • 4,509
  • 3
  • 28
  • 35

2 Answers2

7

Starting in iOS 6, you can check if the item is in iCloud with the following property MPMediaItemPropertyIsCloudItem

https://developer.apple.com/documentation/mediaplayer/mpmediaitempropertyisclouditem?language=objc

Since iOS 9.2, you can check MPMediaItemPropertyHasProtectedAsset for DRM. https://developer.apple.com/documentation/mediaplayer/mpmediaitempropertyhasprotectedasset?language=objc

yano
  • 4,095
  • 3
  • 35
  • 68
0

I can't say with absolute certainty that this is the best way to do it, but in my app I just test the MPMediaItem's MPMediaItemPropertyAssetURL property to see if it's nil:

if ([(MPMediaItem*)item valueForProperty:MPMediaItemPropertyAssetURL] == nil) {
  // it's in the cloud
}
ams
  • 796
  • 1
  • 12
  • 22
  • 2
    It wouldn't work since MPMediaItemPropertyAssetURL is nil for DRM protected media as well, so I wouldn't know if the media item is DRM protected or represents something that is in cloud – Manish Ahuja Jul 20 '12 at 09:19
  • 3
    Are you certain about that? In my app, DRM protected content does have `MPMediaItemPropertyAssetURL` set. The way to check if it's DRM protected is to check the AVAsset's `hasProtectedContent` method – ams Jul 20 '12 at 13:53
  • 2
    To get an AVAsset you need the URL for it from MPMediaItem and the URL is not set if it is either DRM protected, downloaded as an cloud resource or somehow not ready. So you cannot even get to the hasProtectedContent property. – Brennan Dec 06 '12 at 23:05