Get Currently Playing
To display the currently playing song, you can use the getCurrentlyPlaying
method. This method returns the currently playing track for the user.
async function getCurrentlyPlaying(userId) { try { const track = await vibify.getCurrentlyPlaying(userId); console.log('Currently Playing:', track); } catch (error) { console.error('Error:', error); }}
getCurrentlyPlaying('user-id');
Or with cURL:
curl -H "x-api-key: (your api key)" http://localhost:3000/currently-playing/user-id
Response
{ "context":{ "type":"collection", "href":"https://api.spotify.com/v1/me/tracks", "external_urls":{ "spotify":"https://open.spotify.com/collection/tracks" }, "uri":"spotify:user:your-name:collection" }, "timestamp":1708349168857, "progress_ms":108311, "is_playing":true, "item":{ "album":{ "album_type":"single", "total_tracks":3, "available_markets":[ "AR", "AU", "..." ], "external_urls":{ "spotify":"https://open.spotify.com/album/5ZrAjc3ME3ghkUikJiYrms" }, "href":"https://api.spotify.com/v1/albums/5ZrAjc3ME3ghkUikJiYrms", "id":"5ZrAjc3ME3ghkUikJiYrms", "images":[ { "url":"https://i.scdn.co/image/ab67616d0000b273db233b9a1978f9dfd28abacf", "height":640, "width":640 }, { "url":"https://i.scdn.co/image/ab67616d00001e02db233b9a1978f9dfd28abacf", "height":300, "width":300 }, { "url":"https://i.scdn.co/image/ab67616d00004851db233b9a1978f9dfd28abacf", "height":64, "width":64 } ], "name":"god of the sunsets", "release_date":"2021-10-06", "release_date_precision":"day", "type":"album", "uri":"spotify:album:5ZrAjc3ME3ghkUikJiYrms", "artists":[ { "external_urls":{ "spotify":"https://open.spotify.com/artist/7oPxPZSk7y5q0fhzpmX5Gi" }, "href":"https://api.spotify.com/v1/artists/7oPxPZSk7y5q0fhzpmX5Gi", "id":"7oPxPZSk7y5q0fhzpmX5Gi", "name":"SEB", "type":"artist", "uri":"spotify:artist:7oPxPZSk7y5q0fhzpmX5Gi" } ] }, "artists":[ { "external_urls":{ "spotify":"https://open.spotify.com/artist/7oPxPZSk7y5q0fhzpmX5Gi" }, "href":"https://api.spotify.com/v1/artists/7oPxPZSk7y5q0fhzpmX5Gi", "id":"7oPxPZSk7y5q0fhzpmX5Gi", "name":"SEB", "type":"artist", "uri":"spotify:artist:7oPxPZSk7y5q0fhzpmX5Gi" } ], "available_markets":[ "AR", "AU", "..." ], "disc_number":1, "duration_ms":124705, "explicit":true, "external_ids":{ "isrc":"USQE92100239" }, "external_urls":{ "spotify":"https://open.spotify.com/track/5gOyjqIifZ9NqVcaIIlqv7" }, "href":"https://api.spotify.com/v1/tracks/5gOyjqIifZ9NqVcaIIlqv7", "id":"5gOyjqIifZ9NqVcaIIlqv7", "name":"god of the sunsets", "popularity":62, "preview_url":"https://p.scdn.co/mp3-preview/9bce2385bbffe5913eb76040508876558b635ab3?cid=bd747a3119c04456abd0edfac3d9d42c", "track_number":2, "type":"track", "uri":"spotify:track:5gOyjqIifZ9NqVcaIIlqv7", "is_local":false }, "currently_playing_type":"track", "actions":{ "disallows":{ "resuming":true } }}