fix: limit playback wait to restores
This commit is contained in:
1 parent
a86dc5bcba
commit
879d6d9435
2 files changed
+12
-4
No files matched your search
@@ -34,6 +34,7 @@ export interface PlayTrackOptions {
|
||||
isLocal?: boolean;
|
||||
showLoadingToast?: boolean;
|
||||
showSuccessToast?: boolean;
|
||||
playbackStartTimeoutMs?: number;
|
||||
}
|
||||
|
||||
export interface MediaMetadata {
|
||||
@@ -66,9 +67,13 @@ export async function playTrack(
|
||||
track: PlayingTrack,
|
||||
options: PlayTrackOptions = {}
|
||||
): Promise<boolean> {
|
||||
const { isLocal = false, showLoadingToast = true, showSuccessToast = true } = options;
|
||||
const {
|
||||
isLocal = false,
|
||||
showLoadingToast = true,
|
||||
showSuccessToast = true,
|
||||
playbackStartTimeoutMs = 6000
|
||||
} = options;
|
||||
const shouldAwaitPlayback = showLoadingToast && !isCasting();
|
||||
const playbackStartTimeoutMs = 25000;
|
||||
|
||||
// Set current track in store
|
||||
setCurrentTrack(track);
|
||||
|
||||
@@ -80,6 +80,9 @@ let onTrackEnded: (() => Promise<void>) | null = null;
|
||||
// Session restore state - when set, next play will load the track first
|
||||
let pendingSessionRestore: { trackId: number; position: number } | null = null;
|
||||
|
||||
const PLAYBACK_START_TIMEOUT_MS = 6000;
|
||||
const RESTORE_PLAYBACK_TIMEOUT_MS = 25000;
|
||||
|
||||
// Listeners
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
@@ -264,7 +267,7 @@ export async function togglePlay(): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
await waitForPlaybackStart(trackId, 25000);
|
||||
await waitForPlaybackStart(trackId, RESTORE_PLAYBACK_TIMEOUT_MS);
|
||||
if (currentTrack?.id !== trackId) {
|
||||
return;
|
||||
}
|
||||
@@ -286,7 +289,7 @@ export async function togglePlay(): Promise<void> {
|
||||
showToast(currentTrack.title, 'buffering');
|
||||
await invoke('play_track', { trackId });
|
||||
try {
|
||||
await waitForPlaybackStart(trackId, 25000);
|
||||
await waitForPlaybackStart(trackId, PLAYBACK_START_TIMEOUT_MS);
|
||||
if (currentTrack?.id !== trackId) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user