Checking if a track or album is available for purchase through Apple Music API

Hello, I'm using the Apple Music API to store tracks & albums links in my database and I need a way to determine if a track/album is available for purchase on iTunes or if it's a streaming one.

I'm currently using the "playParams" attribute to determine it. If it is present I consider the track to be streaming, if it's not, I consider it to be a purchasable track.

I'm not sure if this is the best way to do so, I'd gladly take your recommendations, maybe there's an attribute I missed on the API.

Hello @Anemost,

When using Apple Music API directly, the presence of "playParams" in the attributes of a resource of type Songs is indeed a good indicator of whether it is available in the Apple Music catalog for subscription/streaming playback. That said, I don't think you can necessarily assume that a resource of type Songs without "playParams" in its attributes is necessarily available for purchase; the only thing you can conclude is that they're not available for streaming from the Apple Music catalog.

However, if you use the MusicKit framework to access the wealth of content available in Apple Music easily in Swift for apps on Apple platforms, you should know that this relationship between the existence of non-nil playParameters for a Song and its availability for streaming from the Apple Music catalog is no longer valid in iOS 16 and aligned releases.

Indeed, in order to allow playback of library content from the user’s music library, the MusicKit framework may decide to synthesize special values of playParameters that are designed to work with MusicKit’s own players, i.e. SystemMusicPlayer and ApplicationMusicPlayer.

In other words, starting in iOS 16 and aligned releases, the existence of non-nil playParameters for a Song only means that SystemMusicPlayer and ApplicationMusicPlayer are capable of playing that song (provided that the relevant environmental conditions are met at playback time, such as having reachable networking when streaming from the Apple Music catalog is required).

While I hope this information will be helpful, I am also very curious about why you need to know if a track is available for purchase. What is your use-case for this type of information in your app? Feel free to file an enhancement request on Feedback Assistant, including such information about your specific use-case.

Best regards,

Hello Joe and thank you for your answer!

To be honest, I didn't post on the Feedback Assistant because I tried once 6 months ago and never got any answer, not even a confirmation that my feedback was correctly received by the Apple team. But if you tell me that's the way to go I will post there again.

First, my app is web based and developed with PHP & JavaScript, so the MusicKit framework doesn't seem to be an option for me (but tell me if I'm wrong).

My use-case is as follows : I store a lot of links in my database which are all from a specific subgenre. Users visit my website in order to find music for this subgenre and I provide them with links from different music app (Apple Music, Spotify, Deezer) so that they can use my website whatever their music app is.

But multiple users told me that they'd like to get links to purchasable tracks on iTunes too, because some of them prefer buying and have the guarantee of owning the track and not fearing it may disappear from their subscription service due to right issues for example.

Hope this will make it clearer for you

Best regards,

Hi @Anemost,

Thanks for this additional information!

Indeed, if you're building a web app with PHP and JavaScript, you shouldn't try to use the MusicKit framework as found in the native client SDKs for Apple platforms.

You're definitely correct in looking closer at Apple Music API given your target environment. However, I would encourage you to check out the documentation for the new Beta version of MusicKit on the Web, if you haven't already.

I tend to think that a combination of threads in the Developer Forums and tickets in Feedback Assistant works well, especially for bug reports or feature requests: it can get the attention of engineers quickly through the forums, while ensuring that we have a ticket we can use for tracking the investigation internally; that ticket can also contain more information that might not belong in the public forums (like debug logs or a sysdiagnose for bug reports or any other more detailed information that might help us understand the issue or request better). But if it's just a question to clarify some aspect of an API, just starting a thread in the forums is a great start. We can always ask you for a ticket if we feel like it would be beneficial, as I tried to do earlier.

I'll make sure to bring more visibility to this thread and others you've opened recently with my colleagues working on MusicKit on the Web and Apple Music API.

Best regards,

Thanks for your answers.

I created a request in the Feedback Assistant for this (FB10153517), and I hope my feedbacks will help to improve the Apple Music API.

Checking if a track or album is available for purchase through Apple Music API
 
 
Q