Skip to content

Commit 0158230

Browse files
committed
- playing around with the spotify API
1 parent 2d126c5 commit 0158230

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tools/spotify_test.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,32 @@
144144
}
145145
});
146146

147-
// Ready
147+
// Update the 'ready' listener in initializePlayer():
148148
playerInstance.addListener('ready', ({ device_id }) => {
149149
updateStatus(`Ready with Device ID: ${device_id}`);
150+
151+
// Transfer playback automatically
152+
fetch('https://api.spotify.com/v1/me/player', {
153+
method: 'PUT',
154+
headers: {
155+
'Authorization': `Bearer ${token}`,
156+
'Content-Type': 'application/json'
157+
},
158+
body: JSON.stringify({
159+
device_ids: [device_id],
160+
play: false // Set to true if you want to auto-play
161+
})
162+
})
163+
.then(response => {
164+
if (response.status === 204) {
165+
updateStatus('Successfully transferred playback to this device');
166+
} else {
167+
updateStatus('Failed to transfer playback: ' + response.status);
168+
}
169+
})
170+
.catch(error => {
171+
updateStatus('Error transferring playback: ' + error);
172+
});
150173
});
151174

152175
// Not Ready

0 commit comments

Comments
 (0)