how to create a iTunes store URL from a MPMediaItem

My app lets users apply special effects to songs. Currenty I use the MPMediaPickerController and AVAssetReader to select and copy songs from the user's itunes library into my sandbox. I have my own custom player that applies various effects.


This only works if the user has purchased and downloaded the song from iTunes. MPMediaPickerController lets user select Apple Music Songs they may not own. Is there a way to create a URL from the MPMediaItem that would make it easy for the user to purchase this song and download it from iTunes?


Kind regards


Andy

Replies

In order to link to a song, you need the song's identifier. MPMediaItem does not have the song's identifier. So, you have to retrieve it manually using the iTunes Search API. Give the API the song's name, artist, etc., and it will return the song's ID. Then, you can show the song within your app using SKStoreProductViewController.

Wouldn't how this works depend on if the user is a Music subscriber or not? Point is there may not be a fitzal you can employ.

Hi TheCD


When iTunes first introduced the affiliate marketing program and MPMediaPickerController I tried your suggestion. It did not work well enough for me to put it into production. As a test I would go to iTunes and find a song then try and construct a URL from search results. The error rate was unacceptable. Often I would get back a list of songs that did not match my search. That was back in iOS 3 or 4. Apple/itunes affiliate program and api's where targeting web developers. It was obvious at the time that they had not considered iOS app developers. Maybe things have improved


What has your experience been?


Andy

I used the iTunes Search API in an app for several years; I recently shifted to the Apple Music API (I forgot to mention it in my first post). Actually, if you are only retrieving music, you should use the Apple Music API instead. I have found the search to be good enough for user searching.

I took a look. It appears like you can search apple's catalog using the apple music api, how ever there does not seem to be a way to allow the user to purchase the song.

Edit: Added more details in your other thread.