Carry track duration through the queue pipeline
ApiTrackLike/QueueItem had no duration field, so toQueueItem(s) always dropped it and toTrack() hardcoded a new track's duration to 0, relying entirely on the <audio> element's durationchange/loadedmetadata events to fill it in once that track actually became current. Upcoming queue rows never reach that point, so "A continuación" always showed a blank duration even though the backend already returns it. Add duration to both types, thread it through toQueueItems/toQueueItem/ trackFromQueueItem, and seed toTrack() from it. The real-time audio sync still overwrites it once a track actually plays, so this only fills the gap for tracks that haven't played yet. Also map MixItemApplicationResponse's durationSeconds through mixItemTrack, since mixes use a differently-named field.
This commit is contained in:
@@ -13,6 +13,7 @@ export function mixItemTrack(item: MixItem): ApiTrackLike {
|
|||||||
id: item.trackId,
|
id: item.trackId,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
artist: item.artist,
|
artist: item.artist,
|
||||||
|
duration: item.durationSeconds,
|
||||||
listensCount: item.listensCount
|
listensCount: item.listensCount
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export interface QueueItem {
|
|||||||
id: string | number;
|
id: string | number;
|
||||||
title: string;
|
title: string;
|
||||||
artist?: string;
|
artist?: string;
|
||||||
|
duration?: number | string;
|
||||||
explicit?: boolean;
|
explicit?: boolean;
|
||||||
ownerUserId?: string | number | null;
|
ownerUserId?: string | number | null;
|
||||||
listensCount?: number | string;
|
listensCount?: number | string;
|
||||||
@@ -32,6 +33,7 @@ export interface ApiTrackLike {
|
|||||||
id: string | number;
|
id: string | number;
|
||||||
title: string;
|
title: string;
|
||||||
artist?: string | null;
|
artist?: string | null;
|
||||||
|
duration?: number | string;
|
||||||
isExplicit?: boolean;
|
isExplicit?: boolean;
|
||||||
ownerUserId?: string | number | null;
|
ownerUserId?: string | number | null;
|
||||||
listensCount?: number | string;
|
listensCount?: number | string;
|
||||||
@@ -42,6 +44,7 @@ export function toQueueItems(tracks: ApiTrackLike[]): QueueItem[] {
|
|||||||
id: track.id,
|
id: track.id,
|
||||||
title: track.title,
|
title: track.title,
|
||||||
artist: track.artist ?? undefined,
|
artist: track.artist ?? undefined,
|
||||||
|
duration: track.duration,
|
||||||
explicit: track.isExplicit,
|
explicit: track.isExplicit,
|
||||||
ownerUserId: track.ownerUserId,
|
ownerUserId: track.ownerUserId,
|
||||||
listensCount: track.listensCount
|
listensCount: track.listensCount
|
||||||
@@ -57,6 +60,7 @@ export function trackFromQueueItem(item: QueueItem): ApiTrackLike {
|
|||||||
id: item.id,
|
id: item.id,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
artist: item.artist,
|
artist: item.artist,
|
||||||
|
duration: item.duration,
|
||||||
isExplicit: item.explicit,
|
isExplicit: item.explicit,
|
||||||
ownerUserId: item.ownerUserId,
|
ownerUserId: item.ownerUserId,
|
||||||
listensCount: item.listensCount
|
listensCount: item.listensCount
|
||||||
@@ -101,7 +105,7 @@ function toTrack(item: QueueItem): PlayerTrack {
|
|||||||
id: item.id,
|
id: item.id,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
artist: item.artist ?? '',
|
artist: item.artist ?? '',
|
||||||
duration: 0,
|
duration: Number(item.duration) || 0,
|
||||||
explicit: item.explicit,
|
explicit: item.explicit,
|
||||||
ownerUserId: item.ownerUserId,
|
ownerUserId: item.ownerUserId,
|
||||||
listensCount: item.listensCount
|
listensCount: item.listensCount
|
||||||
|
|||||||
Reference in New Issue
Block a user