Skip to content

Commit 260567d

Browse files
committed
- playing around with the spotify API
1 parent e836951 commit 260567d

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

tools/spotify_test.html

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
max-width: 800px;
99
margin: 2rem auto;
1010
padding: 0 1rem;
11-
background-color: #f5f5f5;
11+
background-color: #121212;
12+
color: white;
1213
}
1314
.credentials {
1415
display: flex;
@@ -19,10 +20,23 @@
1920
input {
2021
padding: 0.5rem;
2122
width: 100%;
23+
background: #282828;
24+
border: 1px solid #404040;
25+
color: white;
26+
border-radius: 4px;
2227
}
2328
.setup-button {
24-
padding: 0.5rem 1rem;
29+
padding: 0.75rem 1.5rem;
2530
cursor: pointer;
31+
background: #1DB954;
32+
border: none;
33+
color: white;
34+
border-radius: 4px;
35+
font-weight: bold;
36+
transition: background-color 0.2s;
37+
}
38+
.setup-button:hover {
39+
background: #1ed760;
2640
}
2741
.hidden {
2842
display: none;
@@ -34,18 +48,26 @@
3448
min-height: 80vh;
3549
}
3650
#pauseResumeButton {
37-
width: 80px;
38-
height: 80px;
51+
width: 120px;
52+
height: 120px;
3953
border-radius: 50%;
4054
border: none;
41-
background-color: #1DB954;
55+
background: linear-gradient(145deg, #1DB954, #1ed760);
4256
color: white;
43-
font-size: 24px;
57+
font-size: 28px;
4458
cursor: pointer;
45-
transition: transform 0.2s;
59+
transition: all 0.3s ease;
60+
box-shadow: 0 6px 12px rgba(29, 185, 84, 0.3);
61+
display: flex;
62+
align-items: center;
63+
justify-content: center;
4664
}
4765
#pauseResumeButton:hover {
4866
transform: scale(1.05);
67+
box-shadow: 0 8px 16px rgba(29, 185, 84, 0.4);
68+
}
69+
#pauseResumeButton:active {
70+
transform: scale(0.95);
4971
}
5072
</style>
5173
</head>
@@ -155,12 +177,29 @@
155177
})
156178
});
157179

158-
// Auto-play using button click
180+
// If there's a track ID in the URL
159181
const trackId = getUrlParameter('track');
160182
if (trackId) {
161-
setTimeout(() => {
162-
pauseResumeButton.click();
163-
}, 5000);
183+
// First select the track via API
184+
try {
185+
await fetch('https://api.spotify.com/v1/me/player/play', {
186+
method: 'PUT',
187+
headers: {
188+
'Authorization': `Bearer ${token}`,
189+
'Content-Type': 'application/json'
190+
},
191+
body: JSON.stringify({
192+
uris: [`spotify:track:${trackId}`]
193+
})
194+
});
195+
196+
// Then trigger the play button after 4 seconds
197+
setTimeout(() => {
198+
pauseResumeButton.click();
199+
}, 4000);
200+
} catch (error) {
201+
console.error('Error playing track:', error);
202+
}
164203
}
165204
} catch (error) {
166205
console.error('Error during player initialization:', error);

0 commit comments

Comments
 (0)