Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
Fix login, Fix invalid login, Implement unofficial fixes
Browse files Browse the repository at this point in the history
Implemented unofficial fix: librespot-org/librespot-java#720
  • Loading branch information
werwolf2303 committed Oct 8, 2023
1 parent 670ad19 commit a24ee02
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ public void playbackResumedFromHalt(int chunk, long diff) {

@Override
public @Nullable PlayableId nextPlayable() {
NextPlayable next = state.nextPlayable(conf.autoplayEnabled);
//Prevent exeception when next queue
/*NextPlayable next = state.nextPlayable(conf.autoplayEnabled);
if (next == NextPlayable.AUTOPLAY) {
loadAutoplay();
return null;
Expand All @@ -468,6 +469,42 @@ public void playbackResumedFromHalt(int chunk, long diff) {
if (next != NextPlayable.OK_PLAY && next != NextPlayable.OK_REPEAT)
sink.pause(false);
return state.getCurrentPlayableOrThrow();
} else {
ConsoleLoggingModules.error("Failed loading next song: " + next);
panicState(PlaybackMetrics.Reason.END_PLAY);
return null;
}*/
NextPlayable next = state.nextPlayable(conf.autoplayEnabled);
if (next == NextPlayable.AUTOPLAY) {
loadAutoplay();
return null;
}

if (next.isOk()) {
if (next != NextPlayable.OK_PLAY && next != NextPlayable.OK_REPEAT) {
/*
10/1/2023 tagdara -
This is an attempt to remediate librespot moving to the next track in the queue when there is no next track
in the queue. In adddition to re-queueing the current track, this introduces several race conditions when another
track replaces it, causing metadata conflicts and multiple playbackEnded events.
This is a two part change, which also requires a change in the PlayerSession advanceTo function.
Removing the pause and returning null instead of returning state.getCurrentPlayableOrThrow() (the same track) as the
next playable prevents player confusion about what track is truly up next.
This might have an impact on clicking play again on the only track in the queue, but have not experienced this side effect
in testing.
sink.pause(false);
return state.getCurrentPlayableOrThrow();
*/
ConsoleLoggingModules.info("PLAYER.NEXTPLAYABLE - [CODE CHANGE TEST] - sending null on pause to prevent advance");
return null;
}

return state.getCurrentPlayableOrThrow();
} else {
ConsoleLoggingModules.error("Failed loading next song: " + next);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void addNext() {
* @return Whether the operation was successful
*/
private boolean advanceTo(@NotNull PlayableId id) {
do {
/*do {
PlayerQueueEntry entry = queue.head();
if (entry == null) return false;
if (entry.playable.equals(id)) {
Expand All @@ -116,6 +116,31 @@ private boolean advanceTo(@NotNull PlayableId id) {
return true;
}
} while (queue.advance());
return false; */
do {
PlayerQueueEntry entry = queue.head();
if (entry == null) return false;
if (entry.playable.equals(id)) {
PlayerQueueEntry next = queue.next();
/*
10/1/2023 tagdara -
This is an attempt to remediate librespot moving to the next track in the queue when there is no next track
in the queue. In adddition to re-queueing the current track, this introduces several race conditions when another
track replaces it, causing metadata conflicts and multiple playbackEnded events.
This is a two part change, which also requires a modification to nextPlayable in the Player object.
In the 1.64 code, if next === null, indicating there is no next track in the queue, it was returning true. Instead
since AdvanceTo should not advance to a non-existent next track, we will now return false.
*/
if (next == null) {
ConsoleLoggingModules.info("PLAYERSESSION.advanceTo {}. queue head is already {} and next is null: {}. [CODE CHANGE] returning false", id, next);
return false;
}
if (!next.playable.equals(id))
return true;
}
} while (queue.advance());
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/spotifyxp/dialogs/LoginDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void openWithInvalidAuth() {
public void actionPerformed(ActionEvent e) {
PublicValues.config.write(ConfigValues.username.name, spotifyusernamefield.getText());
PublicValues.config.write(ConfigValues.password.name, usernamepasswordfield.getText());
PublicValues.config.write(ConfigValues.facebook.name, "false");
dialog.dispose();
}
});
Expand Down Expand Up @@ -132,7 +133,7 @@ public void open() {
public void actionPerformed(ActionEvent e) {
PublicValues.config.write(ConfigValues.username.name, spotifyusernamefield.getText());
PublicValues.config.write(ConfigValues.password.name, usernamepasswordfield.getText());
PublicValues.config.write(ConfigValues.facebook.name, "true");
PublicValues.config.write(ConfigValues.facebook.name, "false");
dialog.dispose();
}
});
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/spotifyxp/utils/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.spotifyxp.deps.com.spotify.connectstate.Connect;
import com.spotifyxp.PublicValues;
import com.spotifyxp.configuration.ConfigValues;
import com.spotifyxp.deps.se.michaelthelin.spotify.SpotifyApi;
import com.spotifyxp.deps.xyz.gianlu.librespot.audio.decoders.AudioQuality;
import com.spotifyxp.deps.xyz.gianlu.librespot.core.Session;
import com.spotifyxp.deps.xyz.gianlu.librespot.player.Player;
Expand Down Expand Up @@ -44,14 +45,17 @@ public static Player buildPlayer() throws EOFException {
.build();
try {
Session session;
if(PublicValues.config.get(ConfigValues.facebook.name).equalsIgnoreCase("false") || PublicValues.config.get(ConfigValues.facebook.name).equalsIgnoreCase("")) {
if (PublicValues.config.get(ConfigValues.facebook.name).equalsIgnoreCase("false") || PublicValues.config.get(ConfigValues.facebook.name).equalsIgnoreCase("")) {
session = builder.userPass(PublicValues.config.get(ConfigValues.username.name), PublicValues.config.get(ConfigValues.password.name)).create();
}else{
} else {
session = builder.facebook().create();
}
Player player = new Player(playerconfig, session);
PublicValues.session = session;
return player;
}catch (Session.SpotifyAuthenticationException e) {
new LoginDialog().openWithInvalidAuth();
return buildPlayer();
}catch(Exception e) {
e.printStackTrace();
ConsoleLogging.Throwable(e);
Expand Down

0 comments on commit a24ee02

Please sign in to comment.