5

Is there a way to get the iTunes Store ID for a song from an MPMediaItem?

I'm trying to pull the user's playlists, transfer those to another device, then play the songs using MPMusicPlayerController's setQueueWithStoreIDs. This would require mapping the MPMediaItems to content in the iTunes Store, which is the purpose of iTunes Match, which is included in an Apple Music subscription.

Theoretically, this should be possible for songs that were matched to iTunes content. However, I can't find a property or valueForKey on MPMediaItem or any other class in MPMediaPlayer framework that supports this. The persistentId set of properties are local DB keys and don't tie back to the iTunes content for the item. They don't seem to be the same across devices for the same user either.

Jay Whitsitt
  • 937
  • 9
  • 27

1 Answers1

3

This is now possible in iOS 10.3+ using the playbackStoreID instance property on MPMediaItem.

https://developer.apple.com/documentation/mediaplayer/mpmediaitem/2813404-playbackstoreid

Jay Whitsitt
  • 937
  • 9
  • 27
  • I guess because it is new, playbackStoreID is not always there. It returns "0" sometimes if there is no a playbackStoreID found. I think we still need to use iTunes search API for a more stable solution. – Tim Lin Sep 26 '17 at 13:30
  • I believe `playbackStoreID` will return 0 when the song wasn't matched by iTunes Match – Jay Whitsitt Sep 27 '17 at 13:26
  • 4
    The `playbackStoreID` will return 0 when the song is available on Apple Music but was bought using the iTunes Store... – n1ru4l Dec 17 '18 at 14:01