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;
|
isLocal?: boolean;
|
||||||
showLoadingToast?: boolean;
|
showLoadingToast?: boolean;
|
||||||
showSuccessToast?: boolean;
|
showSuccessToast?: boolean;
|
||||||
|
playbackStartTimeoutMs?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MediaMetadata {
|
export interface MediaMetadata {
|
||||||
@@ -66,9 +67,13 @@ export async function playTrack(
|
|||||||
track: PlayingTrack,
|
track: PlayingTrack,
|
||||||
options: PlayTrackOptions = {}
|
options: PlayTrackOptions = {}
|
||||||
): Promise<boolean> {
|
): 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 shouldAwaitPlayback = showLoadingToast && !isCasting();
|
||||||
const playbackStartTimeoutMs = 25000;
|
|
||||||
|
|
||||||
// Set current track in store
|
// Set current track in store
|
||||||
setCurrentTrack(track);
|
setCurrentTrack(track);
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ let onTrackEnded: (() => Promise<void>) | null = null;
|
|||||||
// Session restore state - when set, next play will load the track first
|
// Session restore state - when set, next play will load the track first
|
||||||
let pendingSessionRestore: { trackId: number; position: number } | null = null;
|
let pendingSessionRestore: { trackId: number; position: number } | null = null;
|
||||||
|
|
||||||
|
const PLAYBACK_START_TIMEOUT_MS = 6000;
|
||||||
|
const RESTORE_PLAYBACK_TIMEOUT_MS = 25000;
|
||||||
|
|
||||||
// Listeners
|
// Listeners
|
||||||
const listeners = new Set<() => void>();
|
const listeners = new Set<() => void>();
|
||||||
|
|
||||||
@@ -264,7 +267,7 @@ export async function togglePlay(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await waitForPlaybackStart(trackId, 25000);
|
await waitForPlaybackStart(trackId, RESTORE_PLAYBACK_TIMEOUT_MS);
|
||||||
if (currentTrack?.id !== trackId) {
|
if (currentTrack?.id !== trackId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -286,7 +289,7 @@ export async function togglePlay(): Promise<void> {
|
|||||||
showToast(currentTrack.title, 'buffering');
|
showToast(currentTrack.title, 'buffering');
|
||||||
await invoke('play_track', { trackId });
|
await invoke('play_track', { trackId });
|
||||||
try {
|
try {
|
||||||
await waitForPlaybackStart(trackId, 25000);
|
await waitForPlaybackStart(trackId, PLAYBACK_START_TIMEOUT_MS);
|
||||||
if (currentTrack?.id !== trackId) {
|
if (currentTrack?.id !== trackId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user