adding playing time for a playlist
This commit is contained in:
+23
-1
@@ -94,6 +94,27 @@ function formatTime(value) {
|
||||
return `${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
// Formats total playing time in the interface language, rounded to minutes.
|
||||
function formatPlayingTime(value) {
|
||||
const totalMinutes = Number.isFinite(value) ? Math.max(0, Math.round(value / 60)) : 0;
|
||||
const hours = Math.floor(totalMinutes / 60);
|
||||
const minutes = totalMinutes % 60;
|
||||
const language = window.RktTranslate.language();
|
||||
const parts = [];
|
||||
if (hours > 0) {
|
||||
parts.push(new Intl.NumberFormat(language, {
|
||||
style: "unit", unit: "hour", unitDisplay: "long",
|
||||
}).format(hours));
|
||||
}
|
||||
if (minutes > 0 || hours === 0) {
|
||||
parts.push(new Intl.NumberFormat(language, {
|
||||
style: "unit", unit: "minute", unitDisplay: "long",
|
||||
}).format(minutes));
|
||||
}
|
||||
const duration = new Intl.ListFormat(language, { style: "long", type: "conjunction" }).format(parts);
|
||||
return t("playingTime", { duration });
|
||||
}
|
||||
|
||||
// Replaces the current status message, using an empty string for no message.
|
||||
function setStatus(message) {
|
||||
elements.status.textContent = message || "";
|
||||
@@ -504,7 +525,8 @@ function renderPlaylist(nextState) {
|
||||
|
||||
elements.playlistEmpty.hidden = nextState.tracks.length > 0;
|
||||
const trackLabel = nextState.tracks.length === 1 ? "oneTrack" : "manyTracks";
|
||||
elements.count.textContent = `${nextState.tracks.length} ${t(trackLabel)}`;
|
||||
const tab = nextState.tabs[nextState.currentTab];
|
||||
elements.count.textContent = `${nextState.tracks.length} ${t(trackLabel)}, ${formatPlayingTime(tab.duration)}`;
|
||||
elements.playlistClear.disabled = nextState.tracks.length === 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user