fix(cast): update play button status and add disconnect handoff
1. Play button fix: After resuming on cast device, update playerStore.isPlaying so the UI shows the correct playing state immediately. 2. Disconnect handoff: When disconnecting from Chromecast/DLNA while playing: - Captures current track and position from cast state - Shows confirm dialog asking if user wants to continue locally - If yes, starts local playback and seeks to saved position - If no, just resets player state This provides seamless transitions in both directions: - Local → Cast: auto-resumes with position - Cast → Local: asks user, then resumes with position
This commit is contained in:
1 parent
d52ebeac20
commit
685efcfd76
2 files changed
+90
-5
No files matched your search
+33
-1
@@ -262,7 +262,8 @@
|
||||
import {
|
||||
subscribe as subscribeCast,
|
||||
getCastState,
|
||||
isCasting
|
||||
isCasting,
|
||||
setOnAskContinueLocally
|
||||
} from '$lib/stores/castStore';
|
||||
|
||||
// Components
|
||||
@@ -2255,6 +2256,37 @@
|
||||
// Ignore storage errors
|
||||
}
|
||||
|
||||
// Set up callback for cast disconnect handoff
|
||||
setOnAskContinueLocally(async (track, position) => {
|
||||
// Ask user if they want to continue locally
|
||||
const continueLocally = window.confirm(
|
||||
`Continue playing "${track.title}" on this device?`
|
||||
);
|
||||
|
||||
if (continueLocally) {
|
||||
try {
|
||||
// Start local playback
|
||||
await playTrack(track, { showLoadingToast: false });
|
||||
|
||||
// Seek to saved position after a short delay
|
||||
if (position > 5) {
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await playerSeek(position);
|
||||
console.log('[CastHandoff] Seeked to position:', position);
|
||||
} catch (seekErr) {
|
||||
console.log('[CastHandoff] Could not restore position:', seekErr);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[CastHandoff] Failed to resume local playback:', err);
|
||||
}
|
||||
}
|
||||
|
||||
return continueLocally;
|
||||
});
|
||||
|
||||
// Note: loadFavorites() is called in handleLoginSuccess after login is confirmed
|
||||
// This prevents API calls before authentication is complete
|
||||
|
||||
|
||||
Reference in new issue
Block a user