mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
attempt to fix mpv playback sync on song insertion (#1855)
This commit is contained in:
@@ -1717,6 +1717,8 @@ export const subscribeNextSongInsertion = (onChange: (song: QueueSong | undefine
|
|||||||
queueIndex = mapShuffledToQueueIndex(queueIndex, state.queue.shuffled);
|
queueIndex = mapShuffledToQueueIndex(queueIndex, state.queue.shuffled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentSong = queue.items[queueIndex];
|
||||||
|
|
||||||
// Calculate next song based on shuffle and repeat settings
|
// Calculate next song based on shuffle and repeat settings
|
||||||
let nextSong: QueueSong | undefined;
|
let nextSong: QueueSong | undefined;
|
||||||
if (isShuffleEnabled(state)) {
|
if (isShuffleEnabled(state)) {
|
||||||
@@ -1734,20 +1736,25 @@ export const subscribeNextSongInsertion = (onChange: (song: QueueSong | undefine
|
|||||||
nextSong = calculateNextSong(queueIndex, queue.items, repeat);
|
nextSong = calculateNextSong(queueIndex, queue.items, repeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { index: queueIndex, song: nextSong };
|
return {
|
||||||
|
currentUniqueId: currentSong?._uniqueId,
|
||||||
|
nextSong,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
(current, prev) => {
|
(current, prev) => {
|
||||||
// Only trigger if:
|
if (!prev) {
|
||||||
// 1. We have a previous value (not the first call)
|
return;
|
||||||
// 2. Index hasn't changed (not a natural advance)
|
}
|
||||||
// 3. Next song has changed (song was inserted)
|
|
||||||
if (
|
// Still on the same track, but the upcoming song changed (queue edit: insert, reorder, etc.).
|
||||||
prev &&
|
// Do not require the current track's queue index to stay fixed — e.g. inserting *before* the
|
||||||
current.index === prev.index &&
|
// current item shifts its index in `queue.default`, and the old check missed that case.
|
||||||
current.song?._uniqueId !== prev.song?._uniqueId
|
const sameTrackStillPlaying =
|
||||||
) {
|
current.currentUniqueId !== undefined &&
|
||||||
// Index stayed the same but next song changed = insertion at next position
|
current.currentUniqueId === prev.currentUniqueId;
|
||||||
onChange(current.song);
|
|
||||||
|
if (sameTrackStillPlaying && current.nextSong?._uniqueId !== prev.nextSong?._uniqueId) {
|
||||||
|
onChange(current.nextSong);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user