fix(Remote playback): kludge to scrub after stream move
This commit is contained in:
+14
-3
@@ -175,10 +175,20 @@ function createMusicStore() {
|
||||
const genres = await repo.getGenres(libraryId);
|
||||
if (genres.length === 0) return;
|
||||
|
||||
const hasCounts = genres.some(g => g.albumCount != null);
|
||||
// Counts are only *useful* if they actually differentiate genres. Some
|
||||
// servers return Fields=ItemCounts but populate every genre with the same
|
||||
// value (or 0), which leaves the list in its original alphabetical order
|
||||
// after "ranking" — so diversity selection seeds on the first genre and we
|
||||
// get a wall of A-genres ("avangard", "avan-gard", ...) with no Rock.
|
||||
// Treat that as "no usable counts" and fall through to the probe path,
|
||||
// which ranks by genres' real album counts instead.
|
||||
const positiveCounts = genres
|
||||
.map(g => g.albumCount)
|
||||
.filter((c): c is number => c != null && c > 0);
|
||||
const hasUsefulCounts = new Set(positiveCounts).size > 1;
|
||||
|
||||
let genreRows: GenreRow[];
|
||||
if (hasCounts) {
|
||||
if (hasUsefulCounts) {
|
||||
// Rank by reported count, pick a diverse subset, then fetch only those.
|
||||
const ranked = [...genres].sort(
|
||||
(a, b) => (b.albumCount ?? 0) - (a.albumCount ?? 0)
|
||||
@@ -188,7 +198,8 @@ function createMusicStore() {
|
||||
row => row.items.length > 0
|
||||
);
|
||||
} else {
|
||||
// No counts (offline, or a server that ignores Fields=ItemCounts).
|
||||
// No usable counts (offline, a server that ignores Fields=ItemCounts,
|
||||
// or one that returns uniform/zero counts — see hasUsefulCounts above).
|
||||
// The genre list is alphabetical, so probing the first N would only
|
||||
// ever surface A-genres. Sample at an even stride across the whole
|
||||
// list instead, so the probe pool spans A→Z; then drop empties, rank
|
||||
|
||||
@@ -167,6 +167,7 @@ describe("playbackMode store", () => {
|
||||
|
||||
expect(mockInvoke).toHaveBeenCalledWith("playback_mode_transfer_to_remote", {
|
||||
sessionId: "session-456",
|
||||
position: null,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -73,7 +73,10 @@ function createPlaybackModeStore() {
|
||||
* - Polls remote session until track loads
|
||||
* - Stops local playback
|
||||
*/
|
||||
async function transferToRemote(sessionId: string | null | undefined): Promise<void> {
|
||||
async function transferToRemote(
|
||||
sessionId: string | null | undefined,
|
||||
currentPosition?: number,
|
||||
): Promise<void> {
|
||||
console.log("[PlaybackMode] Transferring to remote session:", sessionId);
|
||||
update((s) => ({ ...s, isTransferring: true, transferError: null }));
|
||||
|
||||
@@ -88,10 +91,17 @@ function createPlaybackModeStore() {
|
||||
};
|
||||
|
||||
try {
|
||||
// Pass the caller's current local position so the remote resumes where we
|
||||
// are. The backend can't reliably read this itself: on Linux video plays in
|
||||
// the HTML5 <video> element and the MPV backend reports 0. A null override
|
||||
// falls back to the backend position (correct for Linux audio via MPV).
|
||||
const positionOverride =
|
||||
currentPosition !== undefined && currentPosition > 0 ? currentPosition : null;
|
||||
|
||||
// Rust handles everything - just wait for it to complete
|
||||
// It includes its own 5-second timeout for track loading
|
||||
console.log("[PlaybackMode] About to invoke playback_mode_transfer_to_remote with sessionId:", sessionId);
|
||||
await commands.playbackModeTransferToRemote(sessionId ?? "");
|
||||
console.log("[PlaybackMode] About to invoke playback_mode_transfer_to_remote with sessionId:", sessionId, "position:", positionOverride);
|
||||
await commands.playbackModeTransferToRemote(sessionId ?? "", positionOverride);
|
||||
console.log("[PlaybackMode] Invoke completed successfully");
|
||||
|
||||
if (aborted) {
|
||||
|
||||
Reference in New Issue
Block a user