Skip to content

Commit 233c89e

Browse files
committed
- playing around with the spotify API
1 parent c4d14ae commit 233c89e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

tools/spotify_test.html

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@
3838
<button onclick="togglePlay()">Play/Pause</button>
3939
</div>
4040

41-
<script src="https://sdk.scdn.co/spotify-player.js"></script>
4241
<script>
4342
let playerInstance = null;
4443
const redirectUri = 'http://gptgames.dev/tools/spotify_test.html';
4544

45+
window.onSpotifyWebPlaybackSDKReady = () => {
46+
const params = getHashParams();
47+
if (params.access_token) {
48+
initializePlayer(params.access_token);
49+
}
50+
};
51+
4652
async function startAuth() {
4753
const clientId = document.getElementById('clientId').value;
4854
const state = Math.random().toString(36).substring(7);
4955
const scope = 'streaming user-read-email user-read-private';
5056

51-
// Using Implicit Grant Flow instead of Authorization Code Flow
5257
const authUrl = `https://accounts.spotify.com/authorize?client_id=${clientId}` +
5358
`&response_type=token` +
5459
`&redirect_uri=${encodeURIComponent(redirectUri)}` +
@@ -103,14 +108,7 @@
103108
playerInstance.togglePlay();
104109
}
105110
}
106-
107-
// Check if we're returning from auth
108-
if (window.location.hash) {
109-
const params = getHashParams();
110-
if (params.access_token) {
111-
initializePlayer(params.access_token);
112-
}
113-
}
114111
</script>
112+
<script src="https://sdk.scdn.co/spotify-player.js"></script>
115113
</body>
116114
</html>

0 commit comments

Comments
 (0)