问题
If I am based in the US and I want to play the song "Sun" by Two Door Cinema Club I would use the ID 544390857
.
I can do this in (for example) the systemMusicPlayer
and the song begins to play in Apple Music.
If my friend is based in the UK and wants to play the same song, sending 544390857
to the systemMusicPlayer results in the song not being recognised (and nothing played).
The GB storefront equivalent ID for that song is 674900368
.
I have two questions:
Is there an easy way of me being able to play the ID from another storefront in Apple Music (using systemMusicPlayer) or would I have to repeat the search under the new, second storefront ID?
or, is there a way of taking one song ID (i.e. the US one) and exchanging it for the alternative (i.e. GB) one?
Thanks for any help you can give!
回答1:
You could try to use Apple Music API to get the right info:
(Step 1 is only needed if you don't know the song name in advance, you only know the songIds)
Based on the storeFrontCountryCode ('US') and songId (matched to that 'US' store) you can get the songName ("Sun"), using 'Get song' API call.
You need to retrieve the user current storeFront. You can do it with requestStorefrontCountryCodeWithCompletionHandler)
You would get something like "GB".
With the songName ('Sun') and the user storeFrontCountryCode ('GB') we do a 'Search for catalog resources' to get the right song id.
Eventually to prevent issues with duplicated song names, you could add the artist name to the 'Search for catalog resources' api call.
回答2:
You can use isrc property of the song to filter a search for song id in another region. From the returned list you can then compare which one is the most match.(ie. a song may appears in multiple albums and has different edits).
The first step would be query the isrc property of the song in the original region. For example:
GET https://api.music.apple.com/v1/catalog/us/songs/544390857
Then you will have the isrc string in the attributes dictionary, then query it in GB storefront:
GET https://api.music.apple.com/v1/catalog/gb/songs?filter[isrc]=XXXXXX
This method is much more accurate than search by song name + artist name.
The Doc link is here: Apple Music API
来源:https://stackoverflow.com/questions/45736402/apple-music-kit-play-song-with-id-from-user-in-storefront-a-for-user-with-stor