diff --git a/lib/src/main/java/xyz/gianlu/librespot/core/Session.java b/lib/src/main/java/xyz/gianlu/librespot/core/Session.java index ac0f92a8..a9530d83 100644 --- a/lib/src/main/java/xyz/gianlu/librespot/core/Session.java +++ b/lib/src/main/java/xyz/gianlu/librespot/core/Session.java @@ -1023,11 +1023,14 @@ public final static class Configuration { // Fetching public final boolean retryOnChunkError; + // Network + public final int connectionTimeout; + private Configuration(boolean proxyEnabled, Proxy.Type proxyType, String proxyAddress, int proxyPort, boolean proxyAuth, String proxyUsername, String proxyPassword, TimeProvider.Method timeSynchronizationMethod, int timeManualCorrection, boolean cacheEnabled, File cacheDir, boolean doCacheCleanUp, boolean storeCredentials, File storedCredentialsFile, - boolean retryOnChunkError) { + boolean retryOnChunkError, int connectionTimeout) { this.proxyEnabled = proxyEnabled; this.proxyType = proxyType; this.proxyAddress = proxyAddress; @@ -1043,6 +1046,7 @@ private Configuration(boolean proxyEnabled, Proxy.Type proxyType, String proxyAd this.storeCredentials = storeCredentials; this.storedCredentialsFile = storedCredentialsFile; this.retryOnChunkError = retryOnChunkError; + this.connectionTimeout = connectionTimeout; } public static final class Builder { @@ -1071,6 +1075,9 @@ public static final class Builder { // Fetching private boolean retryOnChunkError; + // Network + private int connectionTimeout; + public Builder() { } @@ -1149,13 +1156,18 @@ public Builder setRetryOnChunkError(boolean retryOnChunkError) { return this; } + public Builder setConnectionTimeout(int connectionTimeout) { + this.connectionTimeout = connectionTimeout; + return this; + } + @NotNull public Configuration build() { return new Configuration(proxyEnabled, proxyType, proxyAddress, proxyPort, proxyAuth, proxyUsername, proxyPassword, timeSynchronizationMethod, timeManualCorrection, cacheEnabled, cacheDir, doCacheCleanUp, storeCredentials, storedCredentialsFile, - retryOnChunkError); + retryOnChunkError, connectionTimeout); } } } @@ -1298,7 +1310,7 @@ public void run() { scheduledReconnect = scheduler.schedule(() -> { LOGGER.warn("Socket timed out. Reconnecting..."); reconnect(); - }, 2 * 60 + 5, TimeUnit.SECONDS); + }, 2 * 60 + configuration().connectionTimeout, TimeUnit.SECONDS); TimeProvider.updateWithPing(packet.payload); diff --git a/player/src/main/resources/default.toml b/player/src/main/resources/default.toml index ba9d9d0c..f8eb3dda 100644 --- a/player/src/main/resources/default.toml +++ b/player/src/main/resources/default.toml @@ -22,6 +22,9 @@ enabled = true # Cache enabled dir = "./cache/" doCleanUp = true +[network] ### Network ### +connectionTimeout = 10 # If ping isn't received within this amount of seconds, reconnect + [preload] ### Preload ### enabled = true # Preload enabled