|
5 | 5 | <style> |
6 | 6 | body { |
7 | 7 | font-family: Arial, sans-serif; |
8 | | - max-width: 800px; |
9 | | - margin: 2rem auto; |
10 | | - padding: 0 1rem; |
| 8 | + margin: 0; |
| 9 | + padding: 0; |
11 | 10 | background-color: #121212; |
12 | 11 | color: white; |
| 12 | + height: 100vh; |
| 13 | + display: flex; |
| 14 | + flex-direction: column; |
| 15 | + align-items: center; |
13 | 16 | } |
| 17 | + |
14 | 18 | .credentials { |
| 19 | + width: 80%; |
| 20 | + max-width: 500px; |
| 21 | + margin: 2rem auto; |
15 | 22 | display: flex; |
16 | 23 | flex-direction: column; |
17 | 24 | gap: 1rem; |
18 | | - margin-bottom: 2rem; |
19 | 25 | } |
| 26 | + |
20 | 27 | input { |
21 | | - padding: 0.5rem; |
| 28 | + padding: 1rem; |
22 | 29 | width: 100%; |
23 | 30 | background: #282828; |
24 | 31 | border: 1px solid #404040; |
25 | 32 | color: white; |
26 | | - border-radius: 4px; |
| 33 | + border-radius: 8px; |
| 34 | + font-size: 16px; |
27 | 35 | } |
| 36 | + |
28 | 37 | .setup-button { |
29 | | - padding: 0.75rem 1.5rem; |
| 38 | + padding: 1rem; |
30 | 39 | cursor: pointer; |
31 | 40 | background: #1DB954; |
32 | 41 | border: none; |
33 | 42 | color: white; |
34 | | - border-radius: 4px; |
| 43 | + border-radius: 8px; |
| 44 | + font-size: 16px; |
35 | 45 | font-weight: bold; |
36 | | - transition: background-color 0.2s; |
37 | | - } |
38 | | - .setup-button:hover { |
39 | | - background: #1ed760; |
40 | 46 | } |
| 47 | + |
41 | 48 | .hidden { |
42 | 49 | display: none; |
43 | 50 | } |
| 51 | + |
44 | 52 | #player { |
45 | 53 | display: flex; |
46 | 54 | justify-content: center; |
47 | 55 | align-items: center; |
48 | | - min-height: 80vh; |
| 56 | + flex-grow: 1; |
49 | 57 | } |
| 58 | + |
50 | 59 | #pauseResumeButton { |
51 | | - width: 120px; |
52 | | - height: 120px; |
| 60 | + width: 200px; |
| 61 | + height: 200px; |
53 | 62 | border-radius: 50%; |
54 | 63 | border: none; |
55 | | - background: linear-gradient(145deg, #1DB954, #1ed760); |
| 64 | + background: #1DB954; |
56 | 65 | color: white; |
57 | | - font-size: 28px; |
| 66 | + font-size: 60px; |
58 | 67 | 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; |
| 68 | + transition: transform 0.2s; |
| 69 | + box-shadow: 0 8px 16px rgba(0,0,0,0.3); |
64 | 70 | } |
| 71 | + |
65 | 72 | #pauseResumeButton:hover { |
66 | 73 | transform: scale(1.05); |
67 | | - box-shadow: 0 8px 16px rgba(29, 185, 84, 0.4); |
68 | 74 | } |
| 75 | + |
69 | 76 | #pauseResumeButton:active { |
70 | 77 | transform: scale(0.95); |
71 | 78 | } |
|
144 | 151 | playerInstance = new Spotify.Player({ |
145 | 152 | name: 'Development Player', |
146 | 153 | getOAuthToken: cb => { cb(token); }, |
147 | | - volume: 0.5 |
| 154 | + volume: 1.0 |
148 | 155 | }); |
149 | 156 |
|
150 | 157 | playerInstance.addListener('initialization_error', () => { |
|
165 | 172 |
|
166 | 173 | playerInstance.addListener('ready', async ({ device_id }) => { |
167 | 174 | try { |
| 175 | + // First, become active device |
168 | 176 | await fetch('https://api.spotify.com/v1/me/player', { |
169 | 177 | method: 'PUT', |
170 | 178 | headers: { |
|
173 | 181 | }, |
174 | 182 | body: JSON.stringify({ |
175 | 183 | device_ids: [device_id], |
176 | | - play: false |
| 184 | + play: true // Changed to true to ensure playback starts |
177 | 185 | }) |
178 | 186 | }); |
179 | 187 |
|
| 188 | + // Then, after a short delay, play the track if specified |
180 | 189 | const trackId = getUrlParameter('track'); |
181 | 190 | if (trackId) { |
182 | | - try { |
183 | | - await fetch('https://api.spotify.com/v1/me/player/play', { |
184 | | - method: 'PUT', |
185 | | - headers: { |
186 | | - 'Authorization': `Bearer ${token}`, |
187 | | - 'Content-Type': 'application/json' |
188 | | - }, |
189 | | - body: JSON.stringify({ |
190 | | - uris: [`spotify:track:${trackId}`] |
191 | | - }) |
192 | | - }); |
193 | | - } catch (error) { |
194 | | - console.error('Error playing track:', error); |
195 | | - } |
| 191 | + // Add a small delay to ensure device is ready |
| 192 | + setTimeout(async () => { |
| 193 | + try { |
| 194 | + await fetch(`https://api.spotify.com/v1/me/player/play?device_id=${device_id}`, { |
| 195 | + method: 'PUT', |
| 196 | + headers: { |
| 197 | + 'Authorization': `Bearer ${token}`, |
| 198 | + 'Content-Type': 'application/json' |
| 199 | + }, |
| 200 | + body: JSON.stringify({ |
| 201 | + uris: [`spotify:track:${trackId}`] |
| 202 | + }) |
| 203 | + }); |
| 204 | + } catch (error) { |
| 205 | + console.error('Error playing track:', error); |
| 206 | + } |
| 207 | + }, 1000); |
196 | 208 | } |
197 | 209 | } catch (error) { |
198 | 210 | console.error('Error during player initialization:', error); |
|
0 commit comments