Skip to content

Commit 408ded7

Browse files
committed
- playing around with the spotify API
1 parent 0b3398c commit 408ded7

File tree

1 file changed

+10
-53
lines changed

1 file changed

+10
-53
lines changed

tools/spotify_test.html

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
max-width: 800px;
99
margin: 2rem auto;
1010
padding: 0 1rem;
11-
background-color: #121212;
12-
color: white;
11+
background-color: #f5f5f5;
1312
}
1413
.credentials {
1514
display: flex;
@@ -20,23 +19,10 @@
2019
input {
2120
padding: 0.5rem;
2221
width: 100%;
23-
background: #282828;
24-
border: 1px solid #404040;
25-
color: white;
26-
border-radius: 4px;
2722
}
2823
.setup-button {
29-
padding: 0.75rem 1.5rem;
24+
padding: 0.5rem 1rem;
3025
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;
4026
}
4127
.hidden {
4228
display: none;
@@ -48,26 +34,18 @@
4834
min-height: 80vh;
4935
}
5036
#pauseResumeButton {
51-
width: 120px;
52-
height: 120px;
37+
width: 80px;
38+
height: 80px;
5339
border-radius: 50%;
5440
border: none;
55-
background: linear-gradient(145deg, #1DB954, #1ed760);
41+
background-color: #1DB954;
5642
color: white;
57-
font-size: 28px;
43+
font-size: 24px;
5844
cursor: pointer;
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;
45+
transition: transform 0.2s;
6446
}
6547
#pauseResumeButton:hover {
6648
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);
7149
}
7250
</style>
7351
</head>
@@ -137,27 +115,6 @@
137115
return hashParams;
138116
}
139117

140-
async function playTrackById(trackId) {
141-
const token = localStorage.getItem('spotify_access_token');
142-
try {
143-
const response = await fetch('https://api.spotify.com/v1/me/player/play', {
144-
method: 'PUT',
145-
headers: {
146-
'Authorization': `Bearer ${token}`,
147-
'Content-Type': 'application/json'
148-
},
149-
body: JSON.stringify({
150-
uris: [`spotify:track:${trackId}`]
151-
})
152-
});
153-
if (response.status === 204) {
154-
updatePauseResumeButton(true);
155-
}
156-
} catch (error) {
157-
console.error('Error playing track:', error);
158-
}
159-
}
160-
161118
function initializePlayer(token) {
162119
document.getElementById('setup').classList.add('hidden');
163120
document.getElementById('player').classList.remove('hidden');
@@ -198,12 +155,12 @@
198155
})
199156
});
200157

201-
// Auto-play the track if track ID is present in URL
158+
// Auto-play using button click
202159
const trackId = getUrlParameter('track');
203160
if (trackId) {
204161
setTimeout(() => {
205-
playTrackById(trackId);
206-
}, 1000); // Small delay to ensure device is ready
162+
pauseResumeButton.click();
163+
}, 1000);
207164
}
208165
} catch (error) {
209166
console.error('Error during player initialization:', error);

0 commit comments

Comments
 (0)