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