Skip to content

Commit 2bc1904

Browse files
author
werwolf2303
committed
Fixes and Optimizations
Send queue update only after completion Don't test if lyrics are available when not requested Changed reconnect time to 2 seconds
1 parent 538e2e3 commit 2bc1904

File tree

6 files changed

+25
-26
lines changed

6 files changed

+25
-26
lines changed

src/main/java/com/spotifyxp/deps/xyz/gianlu/librespot/core/Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ public void run() {
14451445
scheduledReconnect = scheduler.schedule(() -> {
14461446
ConsoleLoggingModules.warning("Socket timed out. Reconnecting...");
14471447
reconnect();
1448-
}, 120 + configuration().connectionTimeout, TimeUnit.SECONDS);
1448+
}, configuration().connectionTimeout, TimeUnit.SECONDS);
14491449

14501450
TimeProvider.updateWithPing(packet.payload);
14511451

src/main/java/com/spotifyxp/deps/xyz/gianlu/librespot/player/Player.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,13 @@ public void load(@NotNull String uri, boolean play, boolean shuffle) {
273273

274274
public void addToQueue(@NotNull String uri) {
275275
state.addToQueue(ContextTrack.newBuilder().setUri(uri).build());
276-
state.updated();
277276
}
278277

279278
public void removeFromQueue(@NotNull String uri) {
280279
state.removeFromQueue(uri);
280+
}
281+
282+
public void updated() {
281283
state.updated();
282284
}
283285

src/main/java/com/spotifyxp/listeners/PlayerListener.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,23 @@ public void onContextChanged(@NotNull Player player, @NotNull String s) {
8484

8585
@Override
8686
public void onTrackChanged(@NotNull Player player, @NotNull PlayableId playableId, @Nullable MetadataWrapper metadataWrapper, boolean b) {
87-
Events.triggerEvent(SpotifyXPEvents.queueUpdate.getName(), playableId.toSpotifyUri());
88-
if (!TrackUtils.isTrackLiked(playableId.toSpotifyUri().split(":")[2])) {
89-
PlayerArea.heart.isFilled = false;
90-
PlayerArea.heart.setImage(Graphics.HEART.getPath());
91-
} else {
92-
PlayerArea.heart.isFilled = true;
93-
PlayerArea.heart.setImage(Graphics.HEARTFILLED.getPath());
94-
}
95-
if (PlayerArea.playerAreaLyricsButton.isFilled) {
96-
PublicValues.lyricsDialog.open(playableId.toSpotifyUri());
97-
}
98-
if (InstanceManager.getUnofficialSpotifyApi().getLyrics(playableId.toSpotifyUri()) == null) {
99-
PlayerArea.playerAreaLyricsButton.getJComponent().setToolTipText("No lyrics found");
100-
} else {
101-
PlayerArea.playerAreaLyricsButton.getJComponent().setToolTipText(null);
87+
try {
88+
Events.triggerEvent(SpotifyXPEvents.queueUpdate.getName(), playableId.toSpotifyUri());
89+
if (!TrackUtils.isTrackLiked(playableId.toSpotifyUri().split(":")[2])) {
90+
PlayerArea.heart.isFilled = false;
91+
PlayerArea.heart.setImage(Graphics.HEART.getPath());
92+
} else {
93+
PlayerArea.heart.isFilled = true;
94+
PlayerArea.heart.setImage(Graphics.HEARTFILLED.getPath());
95+
}
96+
if (PlayerArea.playerAreaLyricsButton.isFilled) {
97+
PublicValues.lyricsDialog.open(playableId.toSpotifyUri());
98+
}
99+
locked = false;
100+
Events.triggerEvent(SpotifyXPEvents.playerLockRelease.getName());
101+
}catch (Exception e) {
102+
ConsoleLogging.Throwable(e);
102103
}
103-
locked = false;
104-
Events.triggerEvent(SpotifyXPEvents.playerLockRelease.getName());
105104
}
106105

107106
@Override

src/main/java/com/spotifyxp/panels/PlayerArea.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public void mouseClicked(MouseEvent e) {
101101
for (String s : Shuffle.before) {
102102
InstanceManager.getSpotifyPlayer().addToQueue(s);
103103
}
104+
InstanceManager.getSpotifyPlayer().updated();
104105
} catch (Exception e2) {
105106
ConsoleLogging.Throwable(e2);
106107
GraphicalMessage.openException(e2);
@@ -461,13 +462,6 @@ public void run(Object... data) {
461462
playerPlayTime.setText(lastPlayState.playtime);
462463
playerPlayTimeTotal.setText(lastPlayState.playtimetotal);
463464
InstanceManager.getSpotifyPlayer().load(lastPlayState.uri, false, PublicValues.shuffle);
464-
if (!TrackUtils.isTrackLiked(lastPlayState.uri.split(":")[2])) {
465-
heart.isFilled = false;
466-
heart.setImage(Graphics.HEART.getPath());
467-
} else {
468-
heart.isFilled = true;
469-
heart.setImage(Graphics.HEARTFILLED.getPath());
470-
}
471465
InstanceManager.getSpotifyPlayer().seek(lastPlayState.playerslider * 1000);
472466
playerAreaVolumeSlider.setValue(Integer.parseInt(lastPlayState.playervolume));
473467
doneLastParsing = true;
@@ -478,6 +472,7 @@ public void run(Object... data) {
478472
for (String s : lastPlayState.history) {
479473
InstanceManager.getSpotifyPlayer().addToQueue(s);
480474
}
475+
InstanceManager.getSpotifyPlayer().updated();
481476
} catch (Exception ignored) {
482477
ConsoleLogging.warning("Failed to restore player history");
483478
}
@@ -488,6 +483,7 @@ public void run(Object... data) {
488483
for (String s : lastPlayState.queue) {
489484
InstanceManager.getSpotifyPlayer().addToQueue(s);
490485
}
486+
InstanceManager.getSpotifyPlayer().updated();
491487
} catch (Exception ignored) {
492488
ConsoleLogging.warning("Failed to restore player queue");
493489
}

src/main/java/com/spotifyxp/utils/PlayerUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public Player buildPlayer() {
126126
.setLocalFilesPath(new File(PublicValues.fileslocation))
127127
.build();
128128
Session.Configuration.Builder configurationBuilder = new Session.Configuration.Builder()
129+
.setConnectionTimeout(2)
129130
.setCacheDir(new File(PublicValues.fileslocation, "cache"))
130131
.setStoredCredentialsFile(new File(PublicValues.fileslocation, "credentials.json"));
131132
if(PublicValues.config.getBoolean(ConfigValues.cache_disabled.name)) {

src/main/java/com/spotifyxp/utils/Shuffle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public static void makeShuffle() {
3737
for (String s : mixed) {
3838
InstanceManager.getSpotifyPlayer().addToQueue(s);
3939
}
40+
InstanceManager.getSpotifyPlayer().updated();
4041
} catch (Exception e) {
4142
ConsoleLogging.Throwable(e);
4243
GraphicalMessage.openException(e);

0 commit comments

Comments
 (0)