try fix jukebox
This commit is contained in:
parent
447c137e4c
commit
e562c3b459
@ -49,6 +49,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
public static final String ACCESS_TOKEN = "jukebox.access_token";
|
||||
public static final String REFRESH_TOKEN = "jukebox.refresh_token";
|
||||
public static final String EXPIRES = "jukebox.expires";
|
||||
public static final String FALLBACK_CONTEXT_ID = "jukebox.fallbackContextId";
|
||||
|
||||
@Autowired
|
||||
private SystemPropertyManager systemPropertyManager;
|
||||
@ -87,6 +88,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
if (StringUtils.hasText(systemPropertyManager.get(EXPIRES))) {
|
||||
config.setExpires(Instant.parse(systemPropertyManager.get(EXPIRES)));
|
||||
}
|
||||
config.setFallbackContextId(systemPropertyManager.get(FALLBACK_CONTEXT_ID));
|
||||
}
|
||||
|
||||
return config;
|
||||
@ -110,6 +112,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
systemPropertyManager.set(ACTIVE, String.valueOf(config.isActive()));
|
||||
systemPropertyManager.set(ACCESS_TOKEN, config.getAccessToken());
|
||||
systemPropertyManager.set(REFRESH_TOKEN, config.getRefreshToken());
|
||||
systemPropertyManager.set(FALLBACK_CONTEXT_ID, config.getFallbackContextId());
|
||||
|
||||
if (config.getExpires() != null) {
|
||||
systemPropertyManager.set(EXPIRES, config.getExpires().toString());
|
||||
@ -236,6 +239,10 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
}
|
||||
|
||||
protected void tryStartPlayback() {
|
||||
tryStartPlayback(null);
|
||||
}
|
||||
|
||||
protected void tryStartPlayback(String context_uri) {
|
||||
if (!checkToken()) {
|
||||
config.setActive(false);
|
||||
systemPropertyManager.set(ACTIVE, String.valueOf(config.isActive()));
|
||||
@ -251,6 +258,9 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
|
||||
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
|
||||
queryParameters.add("device_id", config.getDeviceId());
|
||||
if (StringUtils.hasText(context_uri)) {
|
||||
queryParameters.add("context_uri", context_uri);
|
||||
}
|
||||
WebClient.RequestBodySpec request = webClient.method(HttpMethod.PUT)
|
||||
.uri(uriBuilder -> uriBuilder.path("/v1/me/player/play")
|
||||
.queryParams(queryParameters).build())
|
||||
@ -261,9 +271,16 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
request.retrieve().bodyToMono(String.class).block();
|
||||
logger.debug("started playback");
|
||||
} catch (Exception e) {
|
||||
config.setActive(false);
|
||||
systemPropertyManager.set(ACTIVE, String.valueOf(config.isActive()));
|
||||
logger.debug("active = false due to failed start playback");
|
||||
if (!StringUtils.hasText(context_uri)
|
||||
&& StringUtils.hasText(config.getFallbackContextId())) {
|
||||
logger.debug("retry to start playback with: "
|
||||
+ config.getFallbackContextId());
|
||||
tryStartPlayback(config.getFallbackContextId());
|
||||
} else {
|
||||
config.setActive(false);
|
||||
systemPropertyManager.set(ACTIVE, String.valueOf(config.isActive()));
|
||||
logger.debug("active = false due to failed start playback");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,7 +367,7 @@ public class JukeboxManager implements SmartInitializingSingleton {
|
||||
logger.debug("discard addToQueue due to missing device id");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
|
||||
queryParameters.add("uri", uri);
|
||||
queryParameters.add("device_id", config.getDeviceId());
|
||||
|
@ -20,6 +20,7 @@ public class JukeboxConfig {
|
||||
private String accessToken;
|
||||
private String refreshToken;
|
||||
private Instant expires;
|
||||
private String fallbackContextId;
|
||||
|
||||
/**
|
||||
* Gets the client id.
|
||||
@ -201,4 +202,18 @@ public class JukeboxConfig {
|
||||
this.expires = expires;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fallbackContextId
|
||||
*/
|
||||
public String getFallbackContextId() {
|
||||
return fallbackContextId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fallbackContextId the fallbackContextId to set
|
||||
*/
|
||||
public void setFallbackContextId(String fallbackContextId) {
|
||||
this.fallbackContextId = fallbackContextId;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user