Music Kit API library ID into something i can use on the device

Hi,


i'm playing around a little bit with the muscia kit REST Api.

As long i'm accesing the catalog, e.g. https://api.music.apple.com/v1/catalog/de/search?term=james+brown&limit=2&types=artists,albums, the api return store ids. I then can use the store ids together with MPMusicPlayerController.

But if i'm accessing my library, the id is something like i.addWKtl6kQE. Is there any way to translate this id in something usefull for MPMusicPlayerController? Right now i'm only able to use the store id and the persistent id together with MPMusicPlayerController.

So from that point there is no connection between playing songs on a device and using the Music Kit API?

  • I am not able to play the song after 30 seconds i am getting preview url in the api not the full song url is there any update on this ? Thanks

Add a Comment

Replies

I ended up using the following logic on song results returned from library APIs (not catalog APIs):

check "playParams", if "catalogId" is there then use it:

            "playParams":{
               "id":"i.oOdKEpmsOO4rLK",
               "kind":"song",
               "isLibrary":true,
               "reporting":true,
               "catalogId":"1468910018"
            },

else check "playParams", if "purchasedId" is there then collect it:

            "playParams":{
               "id":"i.KoJezZYTddP6zZ",
               "kind":"song",
               "isLibrary":true,
               "reporting":false,
               "purchasedId":"953329401"
            },


After that I make a request to Get Multiple Catalog Songs by ID API (Get Multiple Catalog Songs by ID - Apple Music API | Apple Developer Documentation) with gathered "purchasedId"s (you can also include "catalogId"s to keep the logic simple):


https://api.music.apple.com/v1/catalog/{storefront}/songs?ids=953329401,1189391897,1192687537,273798279,283213617748952

You will notice, that some "purchasedId"s are actually catalog IDs! In my request above I sent 8 purchasedIds and got 6 songs as a result. That's how I filtered stuff not in catalog (most probably synced manually from my mac).


Hope this will help someone.

I finally had something I thought was working for me -


Taking the playParams returned by the music API and passing them into the player like so:


guard let pp = MPMusicPlayerPlayParameters(dictionary: playItem.playParams) else {
   // error
}

// add play params to queue


However, it seems like apple has AGAIN changed the way this works in the last few days. Now I have to pass a play params list with ONLY the catalogId (as id not catalogId and kind: "song"). e.g.


{id: {some catalogIdd), kind: "song"}


Has anyone else on this thread seen a behavior change? Are we going to be able to work with a stable API ever? I want to build on apple music but I'm about ready to switch to a competitive api because it actually has stable endpoints and behavior and versioning instead of pushing random changes. This is very frustrating. I have spent more time hacking my way around this API then I have putting time into the user experience. I don't know how to get clear information here but as it is now the apple music api is not a production level api.

There is a recent "catalog" relationship available on some library content (library-songs, library-music-videos and library-playlists) that can be used for this purpose. This relationship may not always be populated as it's possible have no association with any catalog content such as some uploaded content or purchased music that is not available for streaming.


To get this relationship, a few approaches are available. Here's are some examples using a sample identifier from the original post:


GET /v1/me/library/songs/i.addWKtl6kQE?relate=catalog

Returns the library song resource along with an identifier to some available catalog song resource.


GET /v1/me/library/songs/i.addWKtl6kQE?include=catalog

Returns the library song resource with the available catalog song resource.


GET /v1/me/library/songs/i.addWKtl6kQE/catalog

Returns just the available catalog song resource.


The playParams attribute is not intended for making this association and it is possible for the values it contains to evolve over time.

Post not yet marked as solved Up vote reply of jr. Down vote reply of jr.