Skip to content

Commit

Permalink
feat: add playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
Symbitic committed Jun 9, 2021
1 parent 41e36fb commit 0a5c2ba
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 195 deletions.
2 changes: 2 additions & 0 deletions demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function login(_req, res) {

// your application requests authorization
const scope = [
'playlist-read-collaborative',
'playlist-read-private',
'streaming',
'user-read-email',
'user-read-private',
Expand Down
8 changes: 7 additions & 1 deletion public/demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SpotifyPlayer from './index.mjs';

let token = '';

const uri = 'spotify:album:51QBkcL7S3KYdXSSA0zM9R';
let uri = 'spotify:track:54flyrjcdnQdco7300avMJ';

const loginEl = document.getElementById('login');
const playEl = document.getElementById('play');
Expand All @@ -28,6 +28,12 @@ connectButtonEl.addEventListener('click', async () => {
try {
const ret = await spotify.connect(token);
if (ret) {
const playlists = await spotify.getUsersPlaylists();

// Play a random track from the user's favorites.
const idx = Math.floor(Math.random() * playlists[0].tracks.length)
uri = playlists[0].tracks[idx].uri;

playEl.style.display = 'initial';
connectEl.style.display = 'none';
} else {
Expand Down
Loading

0 comments on commit 0a5c2ba

Please sign in to comment.