Spotify now starts playing the latest song if the queue was empty before and then a song was added

This commit is contained in:
Jurn Wubben 2026-02-01 18:47:42 +01:00
parent e9fdc05c2d
commit 63dec0ede2
2 changed files with 13 additions and 4 deletions

View file

@ -231,9 +231,9 @@ class SpotiQueue {
this.socket && this.socket.readyState === WebSocket.OPEN && this.socket && this.socket.readyState === WebSocket.OPEN &&
!this.startedPlaying !this.startedPlaying
) { ) {
Spicetify.Player.pause();
console.log("[SpotiQueue] Requesting new song..."); console.log("[SpotiQueue] Requesting new song...");
this.send({ c: "next_song" }); this.send({ c: "next_song" });
Spicetify.Player.pause();
} }
this.startedPlaying = false; this.startedPlaying = false;
}); });

View file

@ -10,8 +10,10 @@ export type MergedQueue = { user: string; song: Song }[];
export class PlayerManager { export class PlayerManager {
private userQueue: { [x: string]: UserQueue } = {}; private userQueue: { [x: string]: UserQueue } = {};
private nextUserIndex = 0; private nextUserIndex = 0;
private queueStopped = false;
public mergedQueue: MergedQueue = []; public mergedQueue: MergedQueue = [];
public login(name: string, userWS: UserWS): UserQueue { public login(name: string, userWS: UserWS): UserQueue {
if (name in this.userQueue) { if (name in this.userQueue) {
const user = this.userQueue[name]; const user = this.userQueue[name];
@ -23,8 +25,7 @@ export class PlayerManager {
} }
this.userQueue[name] = { this.userQueue[name] = {
queue: [], queue: [], userWS,
userWS,
}; };
return this.userQueue[name]; return this.userQueue[name];
@ -39,7 +40,10 @@ export class PlayerManager {
} }
public getNext(): Song | null { public getNext(): Song | null {
const song = this.mergedQueue.shift(); const song = this.mergedQueue.shift();
if (song === undefined) return null; if (song === undefined) {
this.queueStopped = true;
return null
};
if (song.user in this.userQueue) { if (song.user in this.userQueue) {
const user = this.userQueue[song.user]; const user = this.userQueue[song.user];
@ -57,6 +61,11 @@ export class PlayerManager {
public updateMergedQueue() { public updateMergedQueue() {
this.generateMergedQueue(); this.generateMergedQueue();
this.broadcastMergedQueue(); this.broadcastMergedQueue();
if (this.queueStopped && this.mergedQueue.length > 0) {
this.queueStopped = false;
spotify?.sendSong();
}
} }
private broadcastMergedQueue() { private broadcastMergedQueue() {
for (const user of Object.values(this.userQueue)) { for (const user of Object.values(this.userQueue)) {