Skip to content

Commit 0a5c2ba

Browse files
committed
feat: add playlists
1 parent 41e36fb commit 0a5c2ba

File tree

5 files changed

+325
-195
lines changed

5 files changed

+325
-195
lines changed

demo.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function login(_req, res) {
2626

2727
// your application requests authorization
2828
const scope = [
29+
'playlist-read-collaborative',
30+
'playlist-read-private',
2931
'streaming',
3032
'user-read-email',
3133
'user-read-private',

public/demo.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import SpotifyPlayer from './index.mjs';
22

33
let token = '';
44

5-
const uri = 'spotify:album:51QBkcL7S3KYdXSSA0zM9R';
5+
let uri = 'spotify:track:54flyrjcdnQdco7300avMJ';
66

77
const loginEl = document.getElementById('login');
88
const playEl = document.getElementById('play');
@@ -28,6 +28,12 @@ connectButtonEl.addEventListener('click', async () => {
2828
try {
2929
const ret = await spotify.connect(token);
3030
if (ret) {
31+
const playlists = await spotify.getUsersPlaylists();
32+
33+
// Play a random track from the user's favorites.
34+
const idx = Math.floor(Math.random() * playlists[0].tracks.length)
35+
uri = playlists[0].tracks[idx].uri;
36+
3137
playEl.style.display = 'initial';
3238
connectEl.style.display = 'none';
3339
} else {

0 commit comments

Comments
 (0)