update jukebox to play if not running
This commit is contained in:
parent
1db9257889
commit
bf0f280985
@ -369,16 +369,37 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
|
JsonElement status = getStatus();
|
||||||
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();
|
// 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
2
pom.xml
2
pom.xml
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user