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,6 +369,26 @@ public class JukeboxManager implements SmartInitializingSingleton {
return; return;
} }
JsonElement status = getStatus();
// 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>(); MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
queryParameters.add("uri", uri); queryParameters.add("uri", uri);
queryParameters.add("device_id", config.getDeviceId()); queryParameters.add("device_id", config.getDeviceId());
@ -380,6 +400,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
request.retrieve().bodyToMono(String.class).block(); request.retrieve().bodyToMono(String.class).block();
} }
}
/** /**
* Check active. * Check active.

View File

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