I'm trying to make an music streaming app using Spotify API, I followed their documentation, and getting response from API.. but I have doubt can we play song inside our Android app using their API? Because I can't see URL into response to play the song..
EndPoint - https://api.spotify.com/v1/tracks/5TDIVbFchsBtI15FvW6eKI
Response -
{
"album": {
"album_type": "single",
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/5uemEEtB1ZC3s1KM7gReeH"
},
"href": "https://api.spotify.com/v1/artists/5uemEEtB1ZC3s1KM7gReeH",
"id": "5uemEEtB1ZC3s1KM7gReeH",
"name": "MC STAN",
"type": "artist",
"uri": "spotify:artist:5uemEEtB1ZC3s1KM7gReeH"
}
],
"available_markets": [
"AD",
"AE",
"AL",
"AR",
"AT",
"AU",
"BA",
"BE",
"BG",
"BH",
"BO",
"BR",
"BY",
"CA",
"CH",
"CL",
"CO",
"CR",
"CY",
"CZ",
"DE",
"DK",
"DO",
"DZ",
"EC",
"EE",
"EG",
"ES",
"FI",
"FR",
"GB",
"GR",
"GT",
"HK",
"HN",
"HR",
"HU",
"ID",
"IE",
"IL",
"IN",
"IS",
"IT",
"JO",
"JP",
"KW",
"KZ",
"LB",
"LI",
"LT",
"LU",
"LV",
"MA",
"MC",
"MD",
"ME",
"MK",
"MT",
"MX",
"MY",
"NI",
"NL",
"NO",
"NZ",
"OM",
"PA",
"PE",
"PH",
"PL",
"PS",
"PT",
"PY",
"QA",
"RO",
"RS",
"RU",
"SA",
"SE",
"SG",
"SI",
"SK",
"SV",
"TH",
"TN",
"TR",
"TW",
"UA",
"US",
"UY",
"VN",
"XK",
"ZA"
],
"external_urls": {
"spotify": "https://open.spotify.com/album/1ulRfcW1P501Ge3fq6KvNU"
},
"href": "https://api.spotify.com/v1/albums/1ulRfcW1P501Ge3fq6KvNU",
"id": "1ulRfcW1P501Ge3fq6KvNU",
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b273216b11c58f345e50c78560a6",
"width": 640
},
{
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e02216b11c58f345e50c78560a6",
"width": 300
},
{
"height": 64,
"url": "https://i.scdn.co/image/ab67616d00004851216b11c58f345e50c78560a6",
"width": 64
}
],
"name": "Tadipaar",
"release_date": "2021-01-01",
"release_date_precision": "day",
"total_tracks": 1,
"type": "album",
"uri": "spotify:album:1ulRfcW1P501Ge3fq6KvNU"
},
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/5uemEEtB1ZC3s1KM7gReeH"
},
"href": "https://api.spotify.com/v1/artists/5uemEEtB1ZC3s1KM7gReeH",
"id": "5uemEEtB1ZC3s1KM7gReeH",
"name": "MC STAN",
"type": "artist",
"uri": "spotify:artist:5uemEEtB1ZC3s1KM7gReeH"
}
],
"available_markets": [
"AD",
"AE",
"AL",
"AR",
"AT",
"AU",
"BA",
"BE",
"BG",
"BH",
"BO",
"BR",
"BY",
"CA",
"CH",
"CL",
"CO",
"CR",
"CY",
"CZ",
"DE",
"DK",
"DO",
"DZ",
"EC",
"EE",
"EG",
"ES",
"FI",
"FR",
"GB",
"GR",
"GT",
"HK",
"HN",
"HR",
"HU",
"ID",
"IE",
"IL",
"IN",
"IS",
"IT",
"JO",
"JP",
"KW",
"KZ",
"LB",
"LI",
"LT",
"LU",
"LV",
"MA",
"MC",
"MD",
"ME",
"MK",
"MT",
"MX",
"MY",
"NI",
"NL",
"NO",
"NZ",
"OM",
"PA",
"PE",
"PH",
"PL",
"PS",
"PT",
"PY",
"QA",
"RO",
"RS",
"RU",
"SA",
"SE",
"SG",
"SI",
"SK",
"SV",
"TH",
"TN",
"TR",
"TW",
"UA",
"US",
"UY",
"VN",
"XK",
"ZA"
],
"disc_number": 1,
"duration_ms": 466285,
"explicit": true,
"external_ids": {
"isrc": "DGA062031741"
},
"external_urls": {
"spotify": "https://open.spotify.com/track/5TDIVbFchsBtI15FvW6eKI"
},
"href": "https://api.spotify.com/v1/tracks/5TDIVbFchsBtI15FvW6eKI",
"id": "5TDIVbFchsBtI15FvW6eKI",
"is_local": false,
"name": "Tadipaar",
"popularity": 43,
"preview_url": "https://p.scdn.co/mp3-preview/d7fefabdb983ee45b960456800fe3cb6a449df3f?cid=9f3ed289582146cdb3f68ab42c5737af",
"track_number": 1,
"type": "track",
"uri": "spotify:track:5TDIVbFchsBtI15FvW6eKI"
}
So how to Play track inside our App using Spotify API
The preview_url
is a link to a downloadable 30 second mp3 that you can play inside the app.
If you want to play the entire track, you need to enqueue and play it out via the API, using the player endpoints.
In your case, that could be:
https://api.spotify.com/v1/me/player/queue?uri=spotify:track:5TDIVbFchsBtI15FvW6eKI