@@ -83,11 +83,8 @@ void SpotifyPlayer::initialize(QueueHandle_t *pScuiQueue)
83
83
_spotifyClientId = Vault::getInstance ().getSpotifyClientID ();
84
84
_spotifyClientSecret = Vault::getInstance ().getSpotifyClientSecret ();
85
85
86
- _pSpotify = new SpotifyArduino (
87
- client,
88
- _spotifyClientId.c_str (),
89
- _spotifyClientSecret.c_str ()
90
- );
86
+ spotify.lateInit (_spotifyClientId.c_str (), _spotifyClientSecret.c_str (), _spotifyRefreshToken.c_str ());
87
+
91
88
// client is defined in ThingPulse/spotify.h
92
89
client.setCACert (spotify_server_cert);
93
90
@@ -168,7 +165,7 @@ bool SpotifyPlayer::requestRefreshToken()
168
165
spLogI (LOGTAG_PLAYER, " Requesting Spotify refresh token through the browser via auth code." );
169
166
170
167
String spotifyAuthCode = fetchSpotifyAuthCode ();
171
- _spotifyRefreshToken = _pSpotify-> requestAccessTokens (spotifyAuthCode.c_str (), SPOTIFY_REDIRECT_URI);
168
+ _spotifyRefreshToken = spotify. requestAccessTokens (spotifyAuthCode.c_str (), SPOTIFY_REDIRECT_URI);
172
169
SCFileIO::getInstance ().saveFsString (SPOTIFY_REFRESH_TOKEN_FILE_NAME, _spotifyRefreshToken);
173
170
174
171
return true ;
@@ -196,8 +193,8 @@ void SpotifyPlayer::login()
196
193
// - keeps track of the refresh token and its TTL internally
197
194
// - automatically renews the actual access token using the refresh token
198
195
// -> see SpotifyArduino.h#autoTokenRefresh and SpotifyArduino::checkAndRefreshAccessToken() (called before every API function)
199
- _pSpotify-> setRefreshToken (_spotifyRefreshToken.c_str ());
200
- _pSpotify-> refreshAccessToken ();
196
+ spotify. setRefreshToken (_spotifyRefreshToken.c_str ());
197
+ spotify. refreshAccessToken ();
201
198
spLogI (LOGTAG_PLAYER, " Authentication against Spotify done. Refresh token: %s" , _spotifyRefreshToken.c_str ());
202
199
}
203
200
@@ -251,7 +248,7 @@ void SpotifyPlayer::nextSong()
251
248
static_cast <int >(TFTColor::SC_NetworkInProgress));
252
249
if (xSemaphoreTake (_xSemaphoreNetwork, portMAX_DELAY))
253
250
{
254
- if (_pSpotify-> nextTrack ())
251
+ if (spotify. nextTrack ())
255
252
{
256
253
postScuiMessage (SCUIMessageType::UM_STATUS_BOX,
257
254
" " ,
@@ -291,7 +288,7 @@ void SpotifyPlayer::previousSong()
291
288
292
289
if (xSemaphoreTake (_xSemaphoreNetwork, portMAX_DELAY))
293
290
{
294
- if (_pSpotify-> previousTrack ())
291
+ if (spotify. previousTrack ())
295
292
{
296
293
postScuiMessage (SCUIMessageType::UM_STATUS_BOX,
297
294
" " ,
@@ -333,7 +330,7 @@ void SpotifyPlayer::pauseSong()
333
330
postScuiMessage (SCUIMessageType::UM_STATUS_BOX,
334
331
" Making Call" ,
335
332
static_cast <int >(TFTColor::SC_NetworkInProgress));
336
- if (_pSpotify-> pause ())
333
+ if (spotify. pause ())
337
334
{
338
335
postScuiMessage (SCUIMessageType::UM_STATUS_BOX,
339
336
" " ,
@@ -353,7 +350,7 @@ void SpotifyPlayer::pauseSong()
353
350
postScuiMessage (SCUIMessageType::UM_STATUS_BOX,
354
351
" Making Call" ,
355
352
static_cast <int >(TFTColor::SC_NetworkInProgress));
356
- if (_pSpotify-> play ())
353
+ if (spotify. play ())
357
354
{
358
355
postScuiMessage (SCUIMessageType::UM_STATUS_BOX,
359
356
" " ,
@@ -399,7 +396,7 @@ void SpotifyPlayer::refreshCurrentTrack()
399
396
{
400
397
spLogI (LOGTAG_MULTITASK, " Invoking spotify.getCurrentlyPlaying(...)" );
401
398
Monitor::start (MONITOR_ID_SPOTIFY_GET_CURRENTLY_PLAYING, LOGTAG_METRICS, " spotify.getCurrentlyPlaying(...)" );
402
- status = _pSpotify-> getCurrentlyPlaying (SpotifyPlayer::getCurrentlyPlayingCallback, SP_SPOTIFY_MARKET);
399
+ status = spotify. getCurrentlyPlaying (SpotifyPlayer::getCurrentlyPlayingCallback, SP_SPOTIFY_MARKET);
403
400
Monitor::stop (MONITOR_ID_SPOTIFY_GET_CURRENTLY_PLAYING);
404
401
xSemaphoreGive (_xSemaphoreNetwork);
405
402
}
0 commit comments