how to let users purchase a song

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 so I need to have a copy of the audio in my apps sandbox. MusicKit does not let me plug my audio processing into their players stream.


MPMediaPickerController lets user select Apple Music Songs they may not own. These songs can not be copied in to my app's sand box. I can not apply my speical signal processing to the song using the MusicKit player. 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/Apple Music?


I looked at the apple music api. https://developer.apple.com/documentation/applemusicapi you can search apple's catalog, how ever there does not seem to be an api to allow the user to purchase the song?


iTunes has a search API. It seems to be focused on web developers. The search results return a "viewURL" Many years ago I tried this approach it did not work well. My search terms were a combination of song title, artist, album. Often I would get back multiple results or no match at all. To test I started by find a song in the iTunes store so I know it existed and was unique.


https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/


Are there other music services that let you purchase and down load the song into your app's sand box?



Any suggestions would be greatly appreciated.



Andy

Replies

Here's what I would do:


1. Find the song's identifier with the Apple Music API search API.

2. Show an SKStoreProductViewController with the song. Call loadProduct() with the song's identifier. The user can then purchase the song within your app.

3. Observe MPMediaLibraryDidChange to see if/when the song purchase/download is successful. Then search for the song using MPMediaQuery and get the MPMediaItem's asset url.

Thanks. I will give it a try.