File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change 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 ) } ` +
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 >
You can’t perform that action at this time.
0 commit comments