diff --git a/jukebox/src/main/java/de/bstly/we/jukebox/businesslogic/JukeboxManager.java b/jukebox/src/main/java/de/bstly/we/jukebox/businesslogic/JukeboxManager.java index 3c1e1a5..42436ab 100644 --- a/jukebox/src/main/java/de/bstly/we/jukebox/businesslogic/JukeboxManager.java +++ b/jukebox/src/main/java/de/bstly/we/jukebox/businesslogic/JukeboxManager.java @@ -369,16 +369,37 @@ public class JukeboxManager implements SmartInitializingSingleton { return; } - MultiValueMap queryParameters = new LinkedMultiValueMap(); - 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 queryParameters = new LinkedMultiValueMap(); + 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 queryParameters = new LinkedMultiValueMap(); + 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(); + } } /** diff --git a/pom.xml b/pom.xml index 0fec4e8..6d85caa 100755 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ UTF-8 11 2.17.1 - 1.6.1-SNAPSHOT + 1.6.2-SNAPSHOT