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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user