4

I want to integrate Apple Music into my app, however I don’t want people to have to log in to Apple Music. I just want to get the preview tracks of songs.

Is that possible?

1 Answer 1

8

It is possible to use the Apple Music API to retrieve a song's 30-second preview without the user needing to log in.

  1. Get a developer token

  2. Issue a request for a song

  3. Parse the response to get a Song previews URL

  4. Playback the song with a streaming media player (e.g. Howler)

Example with cURL:

curl -X GET \
  'https://api.music.apple.com/v1/catalog/us/search?term=drake&types=songs&limit=1' \
  -H 'Authorization: Bearer eyJhbG...'
{
    "results": {
        "songs": {
            "href": "/v1/catalog/us/search?limit=5&term=drake&types=songs",
            "next": "/v1/catalog/us/search?offset=5&term=drake&types=songs",
            "data": [
                {
                    "id": "1384782182",
                    "type": "songs",
                    "href": "/v1/catalog/us/songs/1384782182",
                    "attributes": {
                        "previews": [
                            {
                                "url": "https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/AudioPreview125/v4/f5/bc/9e/f5bc9e9c-d62b-332b-04c4-061018d060fc/mzaf_7200764193324270096.plus.aac.p.m4a"
                            }
                        ]
...

You can play the preview using the browser if you want to:

https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/AudioPreview125/v4/f5/bc/9e/f5bc9e9c-d62b-332b-04c4-061018d060fc/mzaf_7200764193324270096.plus.aac.p.m4a

2
  • Hey can I ask how you created the developer token? I’m having trouble actually getting authorised.
    – Tometoyou
    May 19, 2019 at 9:57
  • Hopefully answered your question
    – roman
    May 19, 2019 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.