update jukebox to play if not running

This commit is contained in:
_Bastler 2022-02-10 08:55:47 +01:00
parent 1db9257889
commit bf0f280985
2 changed files with 31 additions and 10 deletions

View File

@ -369,16 +369,37 @@ public class JukeboxManager implements SmartInitializingSingleton {
return;
}
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
queryParameters.add("uri", uri);
queryParameters.add("device_id", config.getDeviceId());
WebClient.RequestBodySpec request = webClient.method(HttpMethod.POST)
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/queue")
.queryParams(queryParameters).build())
.header(HttpHeaders.AUTHORIZATION, "Bearer "
+ config.getAccessToken());
JsonElement status = getStatus();
request.retrieve().bodyToMono(String.class).block();
// start playing if not running
if (status == null || !status.isJsonObject()) {
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
queryParameters.add("device_id", config.getDeviceId());
WebClient.RequestBodySpec request = webClient.method(HttpMethod.PUT)
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/play")
.queryParams(queryParameters).build())
.header(HttpHeaders.AUTHORIZATION, "Bearer "
+ config.getAccessToken());
JsonObject body = new JsonObject();
JsonArray uris = new JsonArray();
uris.add(uri);
body.add("uris", uris);
request.bodyValue(body.toString());
request.retrieve().bodyToMono(String.class).block();
} else {
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
queryParameters.add("uri", uri);
queryParameters.add("device_id", config.getDeviceId());
WebClient.RequestBodySpec request = webClient.method(HttpMethod.POST)
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/queue")
.queryParams(queryParameters).build())
.header(HttpHeaders.AUTHORIZATION, "Bearer "
+ config.getAccessToken());
request.retrieve().bodyToMono(String.class).block();
}
}
/**

View File

@ -13,7 +13,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<log4j2.version>2.17.1</log4j2.version>
<revision>1.6.1-SNAPSHOT</revision>
<revision>1.6.2-SNAPSHOT</revision>
</properties>
<parent>