jukebox fix
This commit is contained in:
parent
c4a0174c25
commit
2eec3627d2
@ -21,6 +21,7 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
@ -203,8 +204,20 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
JsonObject device = statusObject.getAsJsonObject("device");
|
||||
if (!device.get("id").getAsString().equals(config.getDeviceId())
|
||||
&& StringUtils.hasText(config.getDeviceId())) {
|
||||
logger.debug("different device, try to start playback!");
|
||||
tryStartPlayback();
|
||||
logger.debug("different device, try to transfer playback!");
|
||||
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
|
||||
JsonArray device_ids = new JsonArray();
|
||||
device_ids.add(config.getDeviceId());
|
||||
queryParameters.add("device_ids", device_ids.toString());
|
||||
queryParameters.add("play", "true");
|
||||
request = webClient.method(HttpMethod.PUT)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player")
|
||||
.queryParams(queryParameters).build())
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer "
|
||||
+ config.getAccessToken());
|
||||
|
||||
request.retrieve().bodyToMono(String.class).block();
|
||||
return getStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -216,15 +229,23 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (config.isActive()) {
|
||||
logger.debug("no player body, try to start playback!");
|
||||
tryStartPlayback();
|
||||
}
|
||||
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
|
||||
protected void tryStartPlayback() {
|
||||
if (!checkToken()) {
|
||||
config.setActive(false);
|
||||
systemPropertyManager.set(ACTIVE, String.valueOf(config.isActive()));
|
||||
logger.debug("discard tryStartPlayback due to failed token check");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(config.getDeviceId())) {
|
||||
config.setActive(false);
|
||||
systemPropertyManager.set(ACTIVE, String.valueOf(config.isActive()));
|
||||
logger.debug("discard tryStartPlayback due to missing device id");
|
||||
}
|
||||
|
||||
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
|
||||
queryParameters.add("device_id", config.getDeviceId());
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.PUT)
|
||||
|
Loading…
Reference in New Issue
Block a user