Skip to content

Commit f0faeac

Browse files
authored
Merge pull request #50 from j4cko/main
retrieve contextUri from currentlyPlaying
2 parents 970cf5c + 5dd7e68 commit f0faeac

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

examples/getCurrentlyPlaying/getCurrentlyPlaying.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ void printCurrentlyPlayingToSerial(CurrentlyPlaying currentlyPlaying)
157157
Serial.println(currentlyPlaying.albumUri);
158158
Serial.println();
159159

160+
if (currentlyPlaying.contextUri != NULL)
161+
{
162+
Serial.print("Context URI: ");
163+
Serial.println(currentlyPlaying.contextUri);
164+
Serial.println();
165+
}
166+
160167
long progress = currentlyPlaying.progressMs; // duration passed in the song
161168
long duration = currentlyPlaying.durationMs; // Length of Song
162169
Serial.print("Elapsed time of song (ms): ");
@@ -224,4 +231,4 @@ void loop()
224231
}
225232
requestDueTime = millis() + delayBetweenRequests;
226233
}
227-
}
234+
}

src/SpotifyArduino.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,10 @@ int SpotifyArduino::getCurrentlyPlaying(processCurrentlyPlaying currentlyPlaying
538538
CurrentlyPlaying current;
539539

540540
//Apply Json Filter: https://arduinojson.org/v6/example/filter/
541-
StaticJsonDocument<288> filter;
541+
StaticJsonDocument<320> filter;
542542
filter["is_playing"] = true;
543543
filter["progress_ms"] = true;
544+
filter["context"]["uri"] = true;
544545

545546
JsonObject filter_item = filter.createNestedObject("item");
546547
filter_item["duration_ms"] = true;
@@ -629,6 +630,13 @@ int SpotifyArduino::getCurrentlyPlaying(processCurrentlyPlaying currentlyPlaying
629630
current.progressMs = doc["progress_ms"].as<long>();
630631
current.durationMs = item["duration_ms"].as<long>();
631632

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+
632640
currentlyPlayingCallback(current);
633641
}
634642
else

src/SpotifyArduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ struct CurrentlyPlaying
152152
bool isPlaying;
153153
long progressMs;
154154
long durationMs;
155+
const char *contextUri;
155156
};
156157

157158
typedef void (*processCurrentlyPlaying)(CurrentlyPlaying currentlyPlaying);

0 commit comments

Comments
 (0)