File tree 3 files changed +18
-2
lines changed
examples/getCurrentlyPlaying
3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,13 @@ void printCurrentlyPlayingToSerial(CurrentlyPlaying currentlyPlaying)
157
157
Serial.println (currentlyPlaying.albumUri );
158
158
Serial.println ();
159
159
160
+ if (currentlyPlaying.contextUri != NULL )
161
+ {
162
+ Serial.print (" Context URI: " );
163
+ Serial.println (currentlyPlaying.contextUri );
164
+ Serial.println ();
165
+ }
166
+
160
167
long progress = currentlyPlaying.progressMs ; // duration passed in the song
161
168
long duration = currentlyPlaying.durationMs ; // Length of Song
162
169
Serial.print (" Elapsed time of song (ms): " );
@@ -224,4 +231,4 @@ void loop()
224
231
}
225
232
requestDueTime = millis () + delayBetweenRequests;
226
233
}
227
- }
234
+ }
Original file line number Diff line number Diff line change @@ -538,9 +538,10 @@ int SpotifyArduino::getCurrentlyPlaying(processCurrentlyPlaying currentlyPlaying
538
538
CurrentlyPlaying current;
539
539
540
540
// Apply Json Filter: https://arduinojson.org/v6/example/filter/
541
- StaticJsonDocument<288 > filter;
541
+ StaticJsonDocument<320 > filter;
542
542
filter[" is_playing" ] = true ;
543
543
filter[" progress_ms" ] = true ;
544
+ filter[" context" ][" uri" ] = true ;
544
545
545
546
JsonObject filter_item = filter.createNestedObject (" item" );
546
547
filter_item[" duration_ms" ] = true ;
@@ -629,6 +630,13 @@ int SpotifyArduino::getCurrentlyPlaying(processCurrentlyPlaying currentlyPlaying
629
630
current.progressMs = doc[" progress_ms" ].as <long >();
630
631
current.durationMs = item[" duration_ms" ].as <long >();
631
632
633
+ // context may be null
634
+ if ( ! doc[" context" ].isNull () ){
635
+ current.contextUri = doc[" context" ][" uri" ].as <const char *>();
636
+ } else {
637
+ current.contextUri = NULL ;
638
+ }
639
+
632
640
currentlyPlayingCallback (current);
633
641
}
634
642
else
Original file line number Diff line number Diff line change @@ -152,6 +152,7 @@ struct CurrentlyPlaying
152
152
bool isPlaying;
153
153
long progressMs;
154
154
long durationMs;
155
+ const char *contextUri;
155
156
};
156
157
157
158
typedef void (*processCurrentlyPlaying)(CurrentlyPlaying currentlyPlaying);
You can’t perform that action at this time.
0 commit comments