Skip to content

Commit 0b3398c

Browse files
committed
- playing around with the spotify API
1 parent 77a93ac commit 0b3398c

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

tools/spotify_test.html

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
max-width: 800px;
99
margin: 2rem auto;
1010
padding: 0 1rem;
11+
background-color: #121212;
12+
color: white;
1113
}
1214
.credentials {
1315
display: flex;
@@ -18,10 +20,23 @@
1820
input {
1921
padding: 0.5rem;
2022
width: 100%;
23+
background: #282828;
24+
border: 1px solid #404040;
25+
color: white;
26+
border-radius: 4px;
2127
}
2228
.setup-button {
23-
padding: 0.5rem 1rem;
29+
padding: 0.75rem 1.5rem;
2430
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;
2540
}
2641
.hidden {
2742
display: none;
@@ -32,19 +47,27 @@
3247
align-items: center;
3348
min-height: 80vh;
3449
}
35-
#playPauseButton {
36-
width: 100px;
37-
height: 100px;
50+
#pauseResumeButton {
51+
width: 120px;
52+
height: 120px;
3853
border-radius: 50%;
3954
border: none;
40-
background-color: #1DB954;
55+
background: linear-gradient(145deg, #1DB954, #1ed760);
4156
color: white;
42-
font-size: 24px;
57+
font-size: 28px;
4358
cursor: pointer;
44-
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;
64+
}
65+
#pauseResumeButton:hover {
66+
transform: scale(1.05);
67+
box-shadow: 0 8px 16px rgba(29, 185, 84, 0.4);
4568
}
46-
#playPauseButton:hover {
47-
transform: scale(1.1);
69+
#pauseResumeButton:active {
70+
transform: scale(0.95);
4871
}
4972
</style>
5073
</head>
@@ -54,31 +77,26 @@
5477
<button class="setup-button" onclick="startAuth()">Initialize Player</button>
5578
</div>
5679
<div id="player" class="hidden">
57-
<button id="playPauseButton"></button>
80+
<button id="pauseResumeButton">⏸️</button>
5881
</div>
5982

6083
<script>
6184
let playerInstance = null;
6285
let isPlaying = false;
6386
const redirectUri = 'http://gptgames.dev/tools/spotify_test.html';
64-
const playPauseButton = document.getElementById('playPauseButton');
87+
const pauseResumeButton = document.getElementById('pauseResumeButton');
6588

66-
function togglePlayPause() {
89+
function togglePauseResume() {
6790
if (isPlaying) {
6891
playerInstance.pause();
6992
} else {
70-
const trackId = getUrlParameter('track');
71-
if (trackId) {
72-
playTrackById(trackId);
73-
} else {
74-
playerInstance.resume();
75-
}
93+
playerInstance.resume();
7694
}
7795
}
7896

79-
function updatePlayPauseButton(playing) {
97+
function updatePauseResumeButton(playing) {
8098
isPlaying = playing;
81-
playPauseButton.textContent = isPlaying ? '▐▐' : '▶';
99+
pauseResumeButton.textContent = isPlaying ? '⏸️' : '▶';
82100
}
83101

84102
function getUrlParameter(name) {
@@ -133,7 +151,7 @@
133151
})
134152
});
135153
if (response.status === 204) {
136-
updatePlayPauseButton(true);
154+
updatePauseResumeButton(true);
137155
}
138156
} catch (error) {
139157
console.error('Error playing track:', error);
@@ -162,7 +180,7 @@
162180

163181
playerInstance.addListener('player_state_changed', state => {
164182
if (state) {
165-
updatePlayPauseButton(!state.paused);
183+
updatePauseResumeButton(!state.paused);
166184
}
167185
});
168186

@@ -179,12 +197,20 @@
179197
play: false
180198
})
181199
});
200+
201+
// Auto-play the track if track ID is present in URL
202+
const trackId = getUrlParameter('track');
203+
if (trackId) {
204+
setTimeout(() => {
205+
playTrackById(trackId);
206+
}, 1000); // Small delay to ensure device is ready
207+
}
182208
} catch (error) {
183209
console.error('Error during player initialization:', error);
184210
}
185211
});
186212

187-
playPauseButton.onclick = togglePlayPause;
213+
pauseResumeButton.onclick = togglePauseResume;
188214
playerInstance.connect();
189215
}
190216

0 commit comments

Comments
 (0)