fix: restore MPRIS metadata and playback context on session resume

- Send track metadata to MPRIS on session restore so playerctl
  shows title/artist/album immediately after app restart
- Persist playback context (album, playlist, etc.) to localStorage
  on session save and restore it on startup
- Add buffer_progress to frontend PlaybackEvent type

Closes #240

cc
This commit is contained in:
vicrodh committed 2026-03-31 16:33:07 -06:00
1 parent 6acd843891
commit a87e35d167
2 files changed
+31

No files matched your search

+1
View File
@@ -81,6 +81,7 @@ interface PlaybackEvent {
normalization_gain: number | null; // Active normalization gain factor (null = not applied)
gapless_ready: boolean; // Backend wants next track queued for gapless
gapless_next_track_id: number; // Track ID queued for gapless (0 = none)
buffer_progress?: number | null; // Streaming buffer progress (0-1, null = fully cached)
}
// Queue track from backend (for external track sync)
+30
View File
@@ -280,6 +280,7 @@
showTrackNotification,
updateLastfmNowPlaying,
cleanup as cleanupPlayback,
updateMediaMetadata,
type PlayTrackOptions
} from '$lib/services/playbackService';
import {
@@ -3560,6 +3561,27 @@
samplingRate: track.sample_rate ?? undefined,
});
// Update MPRIS metadata so playerctl shows track info
updateMediaMetadata({
title: track.title,
artist: track.artist,
album: track.album,
durationSecs: track.duration_secs,
coverUrl: track.artwork_url || null
});
// Restore playback context (album, playlist, etc.)
try {
const savedCtx = localStorage.getItem('qbz-playback-context');
if (savedCtx) {
const ctx = JSON.parse(savedCtx);
await setPlaybackContext(ctx.type, ctx.id, ctx.label, ctx.source, ctx.track_ids, ctx.current_position);
console.log(`[Session] Playback context restored: ${ctx.type} · ${ctx.label}`);
}
} catch {
console.debug('[Session] Could not restore playback context');
}
// First play will load a fresh stream instead of seeking
setPendingSessionRestore(track.id);
console.log(`[Session] Track ${track.id} restored visually (paused at 0:00)`);
@@ -3752,6 +3774,14 @@
viewContextId,
viewContextType
);
// Persist playback context for session restore
const ctx = getCurrentContext();
if (ctx) {
localStorage.setItem('qbz-playback-context', JSON.stringify(ctx));
} else {
localStorage.removeItem('qbz-playback-context');
}
console.log('[Session] Session saved on close');
} catch (err) {
console.error('[Session] Failed to save session on close:', err);