diff --git a/docs/technical/theming/Theming.md b/docs/technical/theming/Theming.md
index 54df94a4..5122a2a7 100644
--- a/docs/technical/theming/Theming.md
+++ b/docs/technical/theming/Theming.md
@@ -229,7 +229,7 @@ The rendered page content, navigation and scripts are inserted unescaped with `{
### The Audio Player Bar
-Every authenticated page renders the audio player bar through the `audioPlayer` field of the layout model. The bar is hidden until the user starts playback of a track, album or artist, and the global audio player script shows it, expands it and hides it again. The markup comes from the `shared/audio-player` template of the active theme; when the theme does not provide that template, the application renders its own fallback markup, so the player always has a bar to bind to.
+Every authenticated page renders the audio player bar through the `audioPlayer` field of the layout model. The bar starts hidden, and the global audio player script shows it when playback starts, expands it and hides it again. The markup comes from the `shared/audio-player` template of the active theme; when the theme does not provide that template, the application renders its own fallback markup, so the player always has a bar to bind to.
The bar is fixed to the bottom of the viewport, so the theme owns the room reserved for it on the main content element. A layout must keep these element hooks, which the audio player drives (the two id controls are bound by the global site script, which routes them to the audio player):
@@ -251,7 +251,7 @@ The `shared/audio-player` template receives the following model:
| `assetBase` | The base URL of the theme assets, used by the theme template to reference its own assets. |
| `queueItemTemplate` | The raw source of the `shared/audio-player/queue-item` sub template, inlined by the application into a plain text script element. |
| `playlistItemTemplate` | The raw source of the `shared/audio-player/playlist-item` sub template, inlined by the application into a plain text script element. |
-| `strings` | The localized strings of the bar, keyed by their resource names. A shell template uses `toggleFullHeight` and `toggleVisibility` for its two controls; the player reads the play, pause, mute, unmute, volume, seek and buffering labels from the global scripts configuration instead, so a themed shell does not need to render them. |
+| `strings` | The localized strings of the bar, keyed by their resource names. A shell template uses `toggleFullHeight`, `toggleVisibility`, `previous`, `next`, `shuffle`, `shuffleOff`, `shuffleRelease`, `shuffleArtist`, `shuffleLibrary`, `repeat`, `repeatOff`, `repeatAll`, `repeatOne` and `queue` for its controls; the player reads the play, pause, mute, unmute, volume, seek and buffering labels from the global scripts configuration instead, so a themed shell does not need to render them. |
A theme must reserve the space for the bar itself, as the bundled themes do:
@@ -272,11 +272,18 @@ main.audio-player-full-height {
The application fallback layout, which renders when the active theme cannot be loaded, reserves the room itself, because the application stylesheet does not position the content area of a theme. A theme that omits the rules above leaves the fixed bar overlapping the bottom of the page.
-The markup inside the bar exposes the hook attributes the audio player script binds. A theme that replaces the bar markup must keep all of them; the part of the bar whose hook is missing stays inert. The play affordances of the pages use the `data-audio-player-play` trigger attribute.
+The markup inside the bar exposes the hook attributes the audio player script binds. A theme that replaces the bar markup must keep all of them; the part of the bar whose hook is missing stays inert. The play affordances of the pages use the `data-audio-player-play` trigger attribute, and a play next affordance uses `data-audio-player-play-next`; both read the same descriptor attributes. A track trigger must supply `libraryId`, `trackId`, `albumId` and `artistId`, because the playback manifest route needs all four Ids. An album context trigger supplies `libraryId`, `albumId` and `artistId`, and an artist context trigger supplies `libraryId` and `artistId`. The deprecated `queuechange` event keeps its ordered descriptor array payload for older theme scripts; new code must use `queuestatechange`, whose payload is the compact queue summary.
| Hook attribute | Meaning |
| --- | --- |
| `data-audio-player-play-pause` | The play and pause control. The player adds the `is-playing` class to it while a track plays. |
+| `data-audio-player-previous` | The previous control. It either returns to the previous queue entry or restarts the current track, following the navigation history. |
+| `data-audio-player-next` | The next control. It starts the next queue entry and loads another shuffle or autoplay batch when the queue is at its end. The player sets `disabled` and the `is-disabled` class when there is no next entry. |
+| `data-audio-player-shuffle-control` | The wrapper of the shuffle toggle and its scope menu, so the player can position the menu and close it on an outside click. The player adds `is-menu-open` to the bar container while the menu is open, so a theme can let the menu overflow the bar. |
+| `data-audio-player-shuffle` | The shuffle menu button when a scope menu is present: clicking it always opens the menu, the player sets `aria-haspopup="menu"`, `aria-expanded`, and the `is-active` class while shuffle is on, and it does not set `aria-pressed`. Without a scope menu the control is a plain toggle that exposes `aria-pressed` instead. |
+| `data-audio-player-shuffle-menu` | The shuffle scope menu, hidden with the `hidden` attribute while it is closed. |
+| `data-audio-player-shuffle-scope` | A scope item inside the menu, with the value `off`, `release`, `artist` or `library`. The player toggles `aria-checked` and the `is-selected` class on it; the `off` item is selected while shuffle is off. A scope whose required Ids cannot be resolved from the current queue is disabled with `disabled`, `aria-disabled="true"` and the `is-disabled` class. |
+| `data-audio-player-repeat` | The repeat toggle. The player writes `data-audio-player-repeat-mode` (`off`, `all` or `one`), toggles `aria-pressed`, the `is-active` class and, for one, the `is-one` class. |
| `data-audio-player-progress` | The progress bar, a `role="slider"` element with `tabindex="0"` that the player scrubs and whose ARIA value attributes it writes. It carries `data-audio-player-progress-state` (`idle`, `ready` or `buffering`) and the `is-buffering` class while it loads. |
| `data-audio-player-progress-played` | The played layer of the bar. The player publishes its start and width as the custom properties `--audio-player-progress-played-start` and `--audio-player-progress-played-width`. |
| `data-audio-player-progress-downloaded` | The downloaded but not played layer. `--audio-player-progress-downloaded-start` and `--audio-player-progress-downloaded-width`. |
@@ -288,7 +295,7 @@ The markup inside the bar exposes the hook attributes the audio player script bi
| `data-audio-player-volume` | The volume slider, a `role="slider"` element with `tabindex="0"` that the player scrubs and whose ARIA value attributes it writes. The fill is published as `--audio-player-volume-start` and `--audio-player-volume-width`. |
| `data-audio-player-volume-level` | The volume fill. It carries no geometry of its own: the stylesheet drives it from the custom properties above. |
| `data-audio-player-mute` | The mute toggle. The player toggles the `is-muted` class and the `aria-pressed` state on it. |
-| `data-audio-player-queue` | The queue list of the expanded bar. |
+| `data-audio-player-queue` | The queue list of the expanded bar. The player writes `data-audio-player-queue-entry-id` on every rendered item root, whether it comes from the theme sub template or from the built-in markup, and makes the root focusable, so clicking an item or pressing Enter or Space on it starts that entry. |
Each progress layer also carries `data-audio-player-progress-layer` (`played`, `downloaded` or `undownloaded`) in the markup, so a theme can select a layer by its state as well as by its class. The player writes no inline geometry on any of the bar elements: it publishes the geometry of each state as the custom properties above, which the application stylesheet consumes, so a theme restyles or reorients either bar by consuming the same properties.
@@ -305,11 +312,13 @@ The sub templates are rendered client side by the audio player script with the s
| Template | Fields |
| --- | --- |
-| `queue-item` | `index` (the one based position in the queue), `trackId`, `albumId`, `artistId`, `libraryId`, `title`, `duration` (the formatted `m:ss` duration), `durationSeconds`, `coverArtUrl`, `isCurrent`, `isPlayed` and `isLast`. The item root must keep the `audio-player-queue-item` class, the stylesheet hook of a queue item: the player appends the rendered element as-is, so the class is what lets the theme style it. |
+| `queue-item` | `entryId` (the identity of this occurrence in the queue), `index` (the one based position in the queue), `trackId`, `albumId`, `artistId`, `libraryId`, `title`, `duration` (the formatted `m:ss` duration), `durationSeconds`, `coverArtUrl`, `isCurrent`, `isPlayed`, `isLast`, `isContinuation` (the entry was added by the autoplay continuation) and `isShuffled` (the entry was added by a shuffle batch). The item root must keep the `audio-player-queue-item` class, the stylesheet hook of a queue item: the player appends the rendered element as-is, so the class is what lets the theme style it. The built-in item also adds `is-current`, `is-played`, `is-continuation` and `is-shuffled` to the root. The player writes `data-audio-player-queue-entry-id` on the root itself, so a theme item does not need to render the identity. |
| `playlist-item` | `index`, `trackId`, `albumId`, `artistId`, `libraryId`, `title`, `duration`, `durationSeconds`, `coverArtUrl` and `isCurrent`. The item root must keep the `audio-player-playlist-item` class, the stylesheet hook of a playlist item. Saved playlists do not exist yet, so the shell inlines this sub template for theme authors, but nothing renders it yet; the playlist feature renders the entries of a playlist from it. |
A theme can omit either sub template: the player then renders that part with its own built-in markup. When a theme replaces the shell, it must keep the two plain text script element ids above, the element hooks of the bar, and the `audio-player-container`, `not-shown` and `full-height` classes the player toggles.
+Every field of the `queue-item` and `playlist-item` models is untrusted: titles and identifiers come from file metadata and the music endpoints. Render these fields with the escaped form, `{{field}}`. The template engine also supports the unescaped form `{{{field}}}`, but these models contain no trusted HTML, so unescaped tags must not be used for them. Escaping does not neutralise whitespace in an unquoted attribute, so every model value placed in an attribute must sit inside quoted attribute marks, for example `data-track-id="{{trackId}}"` and never `data-track-id={{trackId}}`.
+
### The Navigation Template (shared/nav-menu)
The navigation template renders the menu of the active theme. Its model contains the site name and two menu structures, one for the mobile menu and one for the desktop menu bar:
diff --git a/src/Lumina.Presentation.Api/Core/Themes/Bundled/editorial-paper.zip b/src/Lumina.Presentation.Api/Core/Themes/Bundled/editorial-paper.zip
index 28b833d9..0888cd02 100644
Binary files a/src/Lumina.Presentation.Api/Core/Themes/Bundled/editorial-paper.zip and b/src/Lumina.Presentation.Api/Core/Themes/Bundled/editorial-paper.zip differ
diff --git a/src/Lumina.Presentation.Api/Core/Themes/Bundled/lumina-default.zip b/src/Lumina.Presentation.Api/Core/Themes/Bundled/lumina-default.zip
index 7f88f073..a83a55bb 100644
Binary files a/src/Lumina.Presentation.Api/Core/Themes/Bundled/lumina-default.zip and b/src/Lumina.Presentation.Api/Core/Themes/Bundled/lumina-default.zip differ
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ar-SA.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ar-SA.resx
index 35d9de2a..d8756a71 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ar-SA.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ar-SA.resx
@@ -180,4 +180,40 @@
نعم
+
+ المقطع السابق
+
+
+ المقطع التالي
+
+
+ تشغيل عشوائي
+
+
+ تشغيل الألبوم عشوائياً
+
+
+ تشغيل الفنان عشوائياً
+
+
+ تشغيل المكتبة عشوائياً
+
+
+ تكرار
+
+
+ التكرار متوقف
+
+
+ تكرار الكل
+
+
+ تكرار مقطع واحد
+
+
+ قائمة التشغيل
+
+
+ تشغيل عشوائي متوقف
+
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.de-DE.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.de-DE.resx
index 66d2225f..2f81b8b7 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.de-DE.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.de-DE.resx
@@ -180,4 +180,40 @@
Ja
+
+ Vorheriger Titel
+
+
+ Nächster Titel
+
+
+ Zufallswiedergabe
+
+
+ Release zufällig abspielen
+
+
+ Interpret zufällig abspielen
+
+
+ Bibliothek zufällig abspielen
+
+
+ Wiederholen
+
+
+ Wiederholung aus
+
+
+ Alle wiederholen
+
+
+ Titel wiederholen
+
+
+ Warteschlange
+
+
+ Zufallswiedergabe aus
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.en-US.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.en-US.resx
index 8af1c8e3..ce26252c 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.en-US.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.en-US.resx
@@ -180,4 +180,40 @@
Yes
+
+ Previous track
+
+
+ Next track
+
+
+ Shuffle
+
+
+ Shuffle release
+
+
+ Shuffle artist
+
+
+ Shuffle library
+
+
+ Repeat
+
+
+ Repeat off
+
+
+ Repeat all
+
+
+ Repeat one
+
+
+ Play queue
+
+
+ Shuffle off
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.es-ES.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.es-ES.resx
index aa48670f..b4ca5eb8 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.es-ES.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.es-ES.resx
@@ -180,4 +180,40 @@
Sí
+
+ Pista anterior
+
+
+ Pista siguiente
+
+
+ Reproducción aleatoria
+
+
+ Aleatorio por álbum
+
+
+ Aleatorio por artista
+
+
+ Aleatorio por biblioteca
+
+
+ Repetir
+
+
+ Repetición desactivada
+
+
+ Repetir todo
+
+
+ Repetir pista
+
+
+ Cola de reproducción
+
+
+ Reproducción aleatoria desactivada
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.fr-FR.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.fr-FR.resx
index 89f415cd..6c76035b 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.fr-FR.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.fr-FR.resx
@@ -180,4 +180,40 @@
Oui
+
+ Piste précédente
+
+
+ Piste suivante
+
+
+ Lecture aléatoire
+
+
+ Aléatoire sur la sortie
+
+
+ Aléatoire sur l’artiste
+
+
+ Aléatoire sur la bibliothèque
+
+
+ Répéter
+
+
+ Répétition désactivée
+
+
+ Tout répéter
+
+
+ Répéter la piste
+
+
+ File de lecture
+
+
+ Lecture aléatoire désactivée
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.it-IT.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.it-IT.resx
index 96e4c685..b743bc30 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.it-IT.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.it-IT.resx
@@ -180,4 +180,40 @@
Sì
+
+ Brano precedente
+
+
+ Brano successivo
+
+
+ Riproduzione casuale
+
+
+ Casuale per album
+
+
+ Casuale per artista
+
+
+ Casuale per libreria
+
+
+ Ripeti
+
+
+ Ripetizione disattivata
+
+
+ Ripeti tutto
+
+
+ Ripeti brano
+
+
+ Coda di riproduzione
+
+
+ Riproduzione casuale disattivata
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ja-JP.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ja-JP.resx
index 498740a1..301beb9a 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ja-JP.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ja-JP.resx
@@ -180,4 +180,40 @@
はい
+
+ 前の曲
+
+
+ 次の曲
+
+
+ シャッフル
+
+
+ アルバムをシャッフル
+
+
+ アーティストをシャッフル
+
+
+ ライブラリをシャッフル
+
+
+ リピート
+
+
+ リピートなし
+
+
+ すべてリピート
+
+
+ 1曲リピート
+
+
+ 再生キュー
+
+
+ シャッフルなし
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.resx
index 8af1c8e3..ce26252c 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.resx
@@ -180,4 +180,40 @@
Yes
+
+ Previous track
+
+
+ Next track
+
+
+ Shuffle
+
+
+ Shuffle release
+
+
+ Shuffle artist
+
+
+ Shuffle library
+
+
+ Repeat
+
+
+ Repeat off
+
+
+ Repeat all
+
+
+ Repeat one
+
+
+ Play queue
+
+
+ Shuffle off
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ro-RO.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ro-RO.resx
index cc6f9de6..6fe040f3 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ro-RO.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.ro-RO.resx
@@ -180,4 +180,40 @@
Da
+
+ Piesa anterioară
+
+
+ Piesa următoare
+
+
+ Redare aleatorie
+
+
+ Aleatoriu pe album
+
+
+ Aleatoriu pe artist
+
+
+ Aleatoriu pe bibliotecă
+
+
+ Repetă
+
+
+ Repetare oprită
+
+
+ Repetă tot
+
+
+ Repetă piesa
+
+
+ Coada de redare
+
+
+ Redare aleatorie oprită
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.uk-UA.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.uk-UA.resx
index 847d6304..747b667d 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.uk-UA.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.uk-UA.resx
@@ -180,4 +180,40 @@
Так
+
+ Попередній трек
+
+
+ Наступний трек
+
+
+ Перемішати
+
+
+ Перемішати альбом
+
+
+ Перемішати виконавця
+
+
+ Перемішати бібліотеку
+
+
+ Повтор
+
+
+ Повтор вимкнено
+
+
+ Повторити все
+
+
+ Повторити трек
+
+
+ Черга відтворення
+
+
+ Перемішування вимкнено
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.zh-CN.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.zh-CN.resx
index 49547c28..63ae135a 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.zh-CN.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Shared/_Layout.zh-CN.resx
@@ -180,4 +180,40 @@
是
+
+ 上一首
+
+
+ 下一首
+
+
+ 随机播放
+
+
+ 随机播放专辑
+
+
+ 随机播放艺术家
+
+
+ 随机播放音乐库
+
+
+ 循环播放
+
+
+ 不循环
+
+
+ 列表循环
+
+
+ 单曲循环
+
+
+ 播放队列
+
+
+ 关闭随机播放
+
\ No newline at end of file
diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerBuilder.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerBuilder.cs
index 6f00a28f..5abe0da3 100644
--- a/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerBuilder.cs
+++ b/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerBuilder.cs
@@ -42,7 +42,19 @@ public sealed class ThemeAudioPlayerBuilder
Dictionary strings = new()
{
["toggleFullHeight"] = Localize("ToggleFullHeight"),
- ["toggleVisibility"] = Localize("ToggleVisibility")
+ ["toggleVisibility"] = Localize("ToggleVisibility"),
+ ["previous"] = Localize("AudioPlayerPrevious"),
+ ["next"] = Localize("AudioPlayerNext"),
+ ["shuffle"] = Localize("AudioPlayerShuffle"),
+ ["shuffleOff"] = Localize("AudioPlayerShuffleOff"),
+ ["shuffleRelease"] = Localize("AudioPlayerShuffleRelease"),
+ ["shuffleArtist"] = Localize("AudioPlayerShuffleArtist"),
+ ["shuffleLibrary"] = Localize("AudioPlayerShuffleLibrary"),
+ ["repeat"] = Localize("AudioPlayerRepeat"),
+ ["repeatOff"] = Localize("AudioPlayerRepeatOff"),
+ ["repeatAll"] = Localize("AudioPlayerRepeatAll"),
+ ["repeatOne"] = Localize("AudioPlayerRepeatOne"),
+ ["queue"] = Localize("AudioPlayerQueue")
};
return new ThemeAudioPlayerDto(
diff --git a/src/Lumina.Presentation.Web/Core/Views/Shared/_AudioPlayer.cshtml b/src/Lumina.Presentation.Web/Core/Views/Shared/_AudioPlayer.cshtml
index 3fb2d034..f2e864f0 100644
--- a/src/Lumina.Presentation.Web/Core/Views/Shared/_AudioPlayer.cshtml
+++ b/src/Lumina.Presentation.Web/Core/Views/Shared/_AudioPlayer.cshtml
@@ -27,11 +27,20 @@
while it is expanded. The audio player toggles both classes on it as well.
- The elements with the ids 'audio-player-full-height-toggle' and 'audio-player-close', which the global site script
binds and routes to the audio player.
- - The hook attributes the audio player binds: 'data-audio-player-play-pause', '-progress', '-progress-played',
- '-progress-downloaded', '-progress-undownloaded', '-current-time', '-total-time', '-track-name',
- '-cover-thumbnail', '-cover-image', '-volume', '-volume-level', '-mute' and '-queue'. The volume fill element
- ('-volume-level') is a styling hook the stylesheet drives from the custom properties below, not one the script
- writes to.
+ - The hook attributes the audio player binds: 'data-audio-player-play-pause', '-previous', '-next', '-shuffle',
+ '-shuffle-control', '-shuffle-menu', '-repeat', '-progress', '-progress-played', '-progress-downloaded',
+ '-progress-undownloaded', '-current-time', '-total-time', '-track-name', '-cover-thumbnail', '-cover-image',
+ '-volume', '-volume-level', '-mute' and '-queue'. The volume fill element ('-volume-level') is a styling hook the
+ stylesheet drives from the custom properties below, not one the script writes to.
+ - The shuffle scope items carry 'data-audio-player-shuffle-scope' ('off', 'release', 'artist' or 'library'), inside
+ the menu element carrying 'data-audio-player-shuffle-menu'. The shuffle control carries 'data-audio-player-shuffle'
+ and is wrapped by 'data-audio-player-shuffle-control', so the player can open the menu near it and close it on an
+ outside click. It is a menu button: it carries 'aria-haspopup' and 'aria-expanded', gets the 'is-active' class while
+ shuffle is on, and does not carry 'aria-pressed'. The scope items get 'aria-checked' and the 'is-selected' class, and
+ the 'off' item is selected while shuffle is off. The repeat toggle carries 'data-audio-player-repeat' and the player
+ writes 'data-audio-player-repeat-mode' ('off', 'all' or 'one') and toggles the 'is-active' and 'is-one' classes on it.
+ A queue item root rendered by the player always carries 'data-audio-player-queue-entry-id', whether it comes from the
+ theme sub template or from the built-in markup, so clicking it starts that entry.
- The three state progress bar: the played part carries 'audio-player-progress-played', the downloaded but not
played part carries 'audio-player-progress-downloaded', and the not yet downloaded part carries
'audio-player-progress-undownloaded'. Each layer also carries 'data-audio-player-progress-layer' ('played',
@@ -43,19 +52,22 @@
geometry, so a theme consumes the properties to style each state and to give either bar its own shape and
orientation. The player marks the bar with 'is-buffering' while it is loading, and carries the state in
'data-audio-player-progress-state' ('idle', 'ready' or 'buffering') together with the slider ARIA attributes.
- - The plain text script elements that carry the raw source of the 'shared/audio-player/queue-item' and
- 'shared/audio-player/playlist-item' sub templates, with the ids 'audio-player-template-queue-item' and
- 'audio-player-template-playlist-item'.
+ - Themed shells only: the plain text script elements that carry the raw source of the
+ 'shared/audio-player/queue-item' and 'shared/audio-player/playlist-item' sub templates, with the ids
+ 'audio-player-template-queue-item' and 'audio-player-template-playlist-item'. This application fallback partial
+ renders neither element; it intentionally uses the built-in queue item markup.
- The play affordances the pages hand to the player use the 'data-audio-player-play' trigger attribute. The
- 'The Audio Player Bar' section of docs/technical/theming/Theming.md documents this contract for theme authors.
+ The play affordances the pages hand to the player use the 'data-audio-player-play' trigger attribute, and a play next
+ affordance uses 'data-audio-player-play-next'. A track trigger must carry libraryId, trackId, albumId and artistId,
+ because the playback manifest route needs all four Ids. The 'The Audio Player Bar' section of
+ docs/technical/theming/Theming.md documents this contract for theme authors.
*@
-
+
@@ -69,9 +81,32 @@
--:--
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Lumina.Presentation.Web/Core/Views/Shared/_ThemeLayoutScripts.cshtml b/src/Lumina.Presentation.Web/Core/Views/Shared/_ThemeLayoutScripts.cshtml
index 2ff409f0..46aa91f2 100644
--- a/src/Lumina.Presentation.Web/Core/Views/Shared/_ThemeLayoutScripts.cshtml
+++ b/src/Lumina.Presentation.Web/Core/Views/Shared/_ThemeLayoutScripts.cshtml
@@ -44,6 +44,12 @@
getPlaybackManifestUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.GET_PLAYBACK_MANIFEST)',
streamTrackRouteTemplate: '@_urlService.GetRelativeUrl(WebRoutes.Music.STREAM_TRACK)',
streamTrackSegmentRouteTemplate: '@_urlService.GetRelativeUrl(WebRoutes.Music.STREAM_TRACK_SEGMENT)',
+ // The endpoints the queue of the player is built from: the releases of an artist, the tracks of a release, and the
+ // artists of a library, which are also the endpoints the autoplay continuation and the library shuffle use. The
+ // queue script documents which context uses which endpoint, and appends the library and pagination query parameters.
+ getArtistsUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.GET_ARTISTS)',
+ getArtistAlbumsUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.GET_ARTIST_ALBUMS)',
+ getAlbumTracksUrl: '@_urlService.GetRelativeUrl(WebRoutes.Music.GET_ALBUM_TRACKS)',
strings: {
play: '@localizer["AudioPlayerPlay"]',
pause: '@localizer["AudioPlayerPause"]',
@@ -51,7 +57,19 @@
unmute: '@localizer["AudioPlayerUnmute"]',
volume: '@localizer["AudioPlayerVolume"]',
seek: '@localizer["AudioPlayerSeek"]',
- buffering: '@localizer["AudioPlayerBuffering"]'
+ buffering: '@localizer["AudioPlayerBuffering"]',
+ previous: '@localizer["AudioPlayerPrevious"]',
+ next: '@localizer["AudioPlayerNext"]',
+ shuffle: '@localizer["AudioPlayerShuffle"]',
+ shuffleOff: '@localizer["AudioPlayerShuffleOff"]',
+ shuffleRelease: '@localizer["AudioPlayerShuffleRelease"]',
+ shuffleArtist: '@localizer["AudioPlayerShuffleArtist"]',
+ shuffleLibrary: '@localizer["AudioPlayerShuffleLibrary"]',
+ repeat: '@localizer["AudioPlayerRepeat"]',
+ repeatOff: '@localizer["AudioPlayerRepeatOff"]',
+ repeatAll: '@localizer["AudioPlayerRepeatAll"]',
+ repeatOne: '@localizer["AudioPlayerRepeatOne"]',
+ queue: '@localizer["AudioPlayerQueue"]'
}
};
@@ -71,6 +89,7 @@
+
diff --git a/src/Lumina.Presentation.Web/wwwroot/css/site.css b/src/Lumina.Presentation.Web/wwwroot/css/site.css
index 0d8fbe4a..2d8ff013 100644
--- a/src/Lumina.Presentation.Web/wwwroot/css/site.css
+++ b/src/Lumina.Presentation.Web/wwwroot/css/site.css
@@ -1274,6 +1274,12 @@ body {
border-top-width: 0px;
}
+/* The shuffle scope menu opens above the bar, so the bar lets it overflow while the menu is open. Every other state keeps
+ the overflow hidden that collapses the bar to its height. */
+.audio-player-container.is-menu-open {
+ overflow: visible;
+}
+
/* The 'hidden' attribute keeps the bar unrendered until the audio player script takes over, so that a page load
never shows it, not even for a frame while the stylesheets settle. The script removes it once the bar is already
in its hidden state, so the removal is never visible. */
@@ -1412,13 +1418,21 @@ html.audio-player-initializing .audio-player-container {
cursor: grabbing;
}
-.audio-player-transport {
+/* The queue controls hold the shuffle scope menu, the skip controls and the repeat toggle. They sit next to the play
+ control, so the bar reads as one transport row. */
+.audio-player-queue-controls {
+ position: relative;
flex: 0 0 auto;
display: flex;
align-items: center;
+ gap: 2px;
}
-.audio-player-play-pause {
+/* The button class is the current hook; the play-pause and mute class names are kept as aliases so a theme that targets
+ those older hooks directly still gets the same box. */
+.audio-player-button,
+.audio-player-play-pause,
+.audio-player-mute {
display: flex;
align-items: center;
justify-content: center;
@@ -1427,9 +1441,113 @@ html.audio-player-initializing .audio-player-container {
padding: 0px;
background-color: transparent;
border: 0px;
+ color: inherit;
cursor: pointer;
}
+.audio-player-button:disabled,
+.audio-player-button.is-disabled,
+.audio-player-play-pause:disabled,
+.audio-player-play-pause.is-disabled,
+.audio-player-mute:disabled,
+.audio-player-mute.is-disabled {
+ opacity: 0.4;
+ cursor: default;
+}
+
+/* The skip icons are drawn with CSS, so a theme restyles them without an image. */
+.audio-player-previous-icon,
+.audio-player-next-icon {
+ display: block;
+ width: 0px;
+ height: 0px;
+ border-style: solid;
+ border-width: 5px 8px 5px 0px;
+ border-color: transparent #E6E6E6 transparent transparent;
+}
+
+.audio-player-previous-icon {
+ box-shadow: -3px 0px 0px #E6E6E6;
+}
+
+.audio-player-next-icon {
+ border-width: 5px 0px 5px 8px;
+ border-color: transparent transparent transparent #E6E6E6;
+ box-shadow: 3px 0px 0px #E6E6E6;
+}
+
+/* The shuffle and repeat glyphs are text, so a theme can replace them with its own imagery while keeping the hooks. */
+.audio-player-shuffle-control {
+ position: relative;
+ display: flex;
+ align-items: center;
+}
+
+.audio-player-shuffle-icon,
+.audio-player-repeat-icon {
+ display: block;
+ font-size: 17px;
+ line-height: 1;
+ color: #E6E6E6;
+}
+
+.audio-player-shuffle.is-active .audio-player-shuffle-icon,
+.audio-player-repeat.is-active .audio-player-repeat-icon {
+ color: #6DCBFE;
+}
+
+.audio-player-repeat {
+ position: relative;
+}
+
+.audio-player-repeat-one-badge {
+ display: none;
+ position: absolute;
+ right: 3px;
+ bottom: 2px;
+ font-size: 9px;
+ line-height: 1;
+ color: #6DCBFE;
+}
+
+.audio-player-repeat.is-one .audio-player-repeat-one-badge {
+ display: block;
+}
+
+/* The shuffle scope menu opens above the control, because the bar is anchored to the bottom of the page. */
+.audio-player-shuffle-menu {
+ position: absolute;
+ right: 0px;
+ bottom: calc(100% + 6px);
+ z-index: 998;
+ display: flex;
+ flex-direction: column;
+ min-width: 150px;
+ padding: 4px;
+ background-color: #1C1C1C;
+ border: 1px solid #444444;
+}
+
+.audio-player-shuffle-menu[hidden] {
+ display: none;
+}
+
+.audio-player-shuffle-menu button {
+ padding: 6px 8px;
+ background: none;
+ border: none;
+ color: inherit;
+ font: inherit;
+ text-align: left;
+ cursor: pointer;
+}
+
+.audio-player-shuffle-menu button:hover,
+.audio-player-shuffle-menu button.is-selected {
+ background-color: #2A2A2A;
+ color: #6DCBFE;
+}
+
/* The play affordance is a right pointing triangle, and the pause affordance two bars, both drawn with CSS
so that a theme can restyle them without an image. */
.audio-player-play-pause-icon {
@@ -1456,18 +1574,6 @@ html.audio-player-initializing .audio-player-container {
gap: 6px;
}
-.audio-player-mute {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 32px;
- height: 32px;
- padding: 0px;
- background-color: transparent;
- border: 0px;
- cursor: pointer;
-}
-
/* The speaker cone of the mute toggle is drawn with CSS, so that a theme restyles it without an image. */
.audio-player-mute-icon {
display: block;
@@ -1558,6 +1664,19 @@ html.audio-player-initializing .audio-player-container {
gap: 12px;
padding: 6px 8px;
border-bottom: 1px solid #333333;
+ cursor: pointer;
+}
+
+.audio-player-queue-item.is-played .audio-player-queue-item-title {
+ color: #8A8A8A;
+}
+
+.audio-player-queue-item.is-current .audio-player-queue-item-title {
+ color: #6DCBFE;
+}
+
+.audio-player-queue-item:focus {
+ outline: 1px solid #6DCBFE;
}
.audio-player-queue-item-title {
diff --git a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-engine.js b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-engine.js
index 8fe463fe..715bc679 100644
--- a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-engine.js
+++ b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-engine.js
@@ -23,6 +23,8 @@
* whether a seek target is buffered, in which case the player never shows a loading state for a seek.
* - discardCurrentAsync() (optional): releases the currently prepared track without destroying the engine, so a stop
* during an automatic continuation does not leave the track it started loaded behind an idle player.
+ * - cancelUpcomingAsync() (optional): drops a prefetched or appended handoff of the current track when the player queue is
+ * replaced under it, for example when shuffle is turned on or off, so audio prepared from the old queue never plays.
* - destroyAsync(): releases every resource the engine holds, including any audio context.
*
* The engine host
@@ -175,8 +177,7 @@
/**
* A registry of engine factories, keyed by name, used to resolve the engine the player runs with.
- * The later stages of the player register the real download, decode and render engine here; the
- * core module only registers the silent engine.
+ * The real download, decode and render engine is registered here; the core module only registers the silent engine.
*/
class PlayerEngineRegistry {
/**
diff --git a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-errors.js b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-errors.js
index 13b03307..3307bd3b 100644
--- a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-errors.js
+++ b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-errors.js
@@ -37,7 +37,9 @@
// The container of a track could not be parsed into encoded packets, or the bytes it holds do not describe a stream the demuxer supports.
DEMUX_FAILED: 'demux-failed',
// The stored playback preferences of the user could not be read.
- PREFERENCES_LOAD_FAILED: 'preferences-load-failed'
+ PREFERENCES_LOAD_FAILED: 'preferences-load-failed',
+ // A play context, a queue batch or a shuffle batch could not be built from the web endpoints.
+ QUEUE_LOAD_FAILED: 'queue-load-failed'
});
/**
diff --git a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-events.js b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-events.js
index 6b887568..6986c169 100644
--- a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-events.js
+++ b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-events.js
@@ -1,7 +1,7 @@
/**
* Event bus of the audio player.
*
- * The player is decoupled from its consumers (the player bar, the transport UI, the queue panel, themes) through a single observable.
+ * The player is decoupled from its consumers (the player bar, the transport UI, the queue panel, themes) through a single observable.
* Every module of the player publishes to this bus, and every consumer subscribes to it, so that no module needs a direct reference to another one.
*/
(function (LuminaAudioPlayer) {
@@ -17,7 +17,11 @@
STATE_CHANGED: 'statechange',
// The currently playing track changed. Payload: the play descriptor.
DESCRIPTOR_CHANGED: 'descriptorchange',
- // The queue changed. Payload: the ordered list of play descriptors.
+ // The playable state of the queue changed: cursor, current entry, counts, repeat mode, shuffle mode or context.
+ // Payload: the compact summary returned by getQueueStateSummary(), not the full queue.
+ QUEUE_STATE_CHANGED: 'queuestatechange',
+ // Deprecated legacy queue event. It keeps its original payload, the ordered list of play descriptors, and is emitted
+ // only when a legacy consumer is subscribed. New code must use QUEUE_STATE_CHANGED and its compact summary.
QUEUE_CHANGED: 'queuechange',
// The playhead moved. Payload: { currentTime, duration }.
TIME_UPDATE: 'timeupdate',
@@ -81,6 +85,16 @@
return () => this.off(event, handler);
}
+ /**
+ * Checks whether an event currently has any subscriber, so a producer can skip an expensive payload nobody reads.
+ * @param {string} event - One of the {@link LuminaAudioPlayer.PlayerEvent} values.
+ * @returns {boolean} True when the event has at least one handler.
+ */
+ hasListeners(event) {
+ const handlers = this.listeners.get(event);
+ return !!handlers && handlers.size > 0;
+ }
+
/**
* Subscribes a handler to an event, removing it after the first emission.
* @param {string} event - One of the {@link LuminaAudioPlayer.PlayerEvent} values.
diff --git a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-manifest.js b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-manifest.js
index c676f31b..83f38ec1 100644
--- a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-manifest.js
+++ b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-manifest.js
@@ -16,16 +16,6 @@
*/
const MANIFEST_REQUEST_TIMEOUT_MS = 20000;
- /**
- * Checks whether a value is a Guid, the only form the manifest route accepts for its Ids.
- * @param {*} value - The value to check.
- * @returns {boolean} True when the value is a Guid string.
- */
- function isGuid(value) {
- return typeof value === 'string'
- && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
- }
-
/**
* Gets the origin this module resolves relative URLs against. The page origin is used in a browser; a fixed local
* origin keeps the route and origin checks testable in a host without a DOM.
@@ -148,11 +138,11 @@
if (!Object.prototype.hasOwnProperty.call(expectedIds, name))
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.ENGINE_LOAD_FAILED, 'The stream route template carries an unknown placeholder.');
const expected = expectedIds[name];
- if (!isGuid(expected))
+ if (!LuminaAudioPlayer.isGuid(expected))
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.INVALID_DESCRIPTOR, `The play descriptor carries no valid ${name}.`, { field: name });
const actual = streamSegments[index];
// The path must describe the track of this descriptor, not merely another track of the same library.
- if (!isGuid(actual) || actual.toLowerCase() !== expected.toLowerCase())
+ if (!LuminaAudioPlayer.isGuid(actual) || actual.toLowerCase() !== expected.toLowerCase())
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.ENGINE_LOAD_FAILED, 'The stream path does not belong to the expected track.');
continue;
}
@@ -167,7 +157,7 @@
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.ENGINE_LOAD_FAILED, 'The stream path does not match the stream route.');
}
const libraryId = descriptor && descriptor.libraryId;
- if (!isGuid(libraryId))
+ if (!LuminaAudioPlayer.isGuid(libraryId))
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.INVALID_DESCRIPTOR, 'The play descriptor carries no valid library Id.', { field: 'libraryId' });
const requestedLibraryIds = url.searchParams.getAll('libraryId');
if (requestedLibraryIds.length !== 1 || requestedLibraryIds[0].toLowerCase() !== libraryId.toLowerCase())
@@ -256,10 +246,10 @@
if (!Object.prototype.hasOwnProperty.call(expectedIds, name))
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.ENGINE_LOAD_FAILED, 'The segment route template carries an unknown placeholder.');
const expected = expectedIds[name];
- if (!isGuid(expected))
+ if (!LuminaAudioPlayer.isGuid(expected))
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.INVALID_DESCRIPTOR, `The play descriptor carries no valid ${name}.`, { field: name });
// The path must describe the track of this descriptor, not merely another track of the same library.
- if (!isGuid(actualSegment) || actualSegment.toLowerCase() !== expected.toLowerCase())
+ if (!LuminaAudioPlayer.isGuid(actualSegment) || actualSegment.toLowerCase() !== expected.toLowerCase())
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.ENGINE_LOAD_FAILED, 'The segment path does not belong to the expected track.');
continue;
}
@@ -267,7 +257,7 @@
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.ENGINE_LOAD_FAILED, 'The segment path does not match the segment route.');
}
const libraryId = descriptor && descriptor.libraryId;
- if (!isGuid(libraryId))
+ if (!LuminaAudioPlayer.isGuid(libraryId))
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.INVALID_DESCRIPTOR, 'The play descriptor carries no valid library Id.', { field: 'libraryId' });
const requestedLibraryIds = url.searchParams.getAll('libraryId');
if (requestedLibraryIds.length !== 1 || requestedLibraryIds[0].toLowerCase() !== libraryId.toLowerCase())
@@ -325,7 +315,7 @@
if (!ids[name])
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.INVALID_DESCRIPTOR, `The play descriptor carries no ${name}.`, { field: name });
// The manifest route only accepts Guids, and a value that is not a Guid must never be interpolated into a path the browser resolves against this origin.
- if (!isGuid(ids[name]))
+ if (!LuminaAudioPlayer.isGuid(ids[name]))
throw new LuminaAudioPlayer.PlayerError(LuminaAudioPlayer.PlayerErrorCode.INVALID_DESCRIPTOR, `The play descriptor carries an invalid ${name}.`, { field: name });
}
let url = String(template)
diff --git a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-pipeline/audio-player-pipeline-engine.js b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-pipeline/audio-player-pipeline-engine.js
index 04941933..ded37d8a 100644
--- a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-pipeline/audio-player-pipeline-engine.js
+++ b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-pipeline/audio-player-pipeline-engine.js
@@ -272,6 +272,40 @@
await this.teardownPlaybackAsync(null, null, false);
}
+ /**
+ * Drops the next item and the prefetch of the current track, without touching the audio that is already playing.
+ *
+ * The player calls it when it replaces the queue under a playing track, for example when the user turns shuffle on or
+ * off. A prefetched or appended handoff was prepared from the queue that no longer exists, so leaving it in place
+ * would play a track the queue no longer describes. When the handoff is already audible it is left alone, because
+ * truncating it would rewind audio that has played.
+ * @returns {Promise} A promise that completes when the upcoming handoff was released.
+ */
+ async cancelUpcomingAsync() {
+ if (this.destroyed)
+ return;
+ const item = this.current;
+ if (!item)
+ return;
+ await this.cancelPrefetchAsync(item);
+ item.continueToEntry = null;
+ const next = this.nextItem;
+ if (!next)
+ return;
+ // A handoff that has not reached the playhead can be removed from the schedule; one that is already audible stays.
+ if (typeof this.renderer.truncateScheduleAt !== 'function'
+ || next.base <= this.renderer.getCurrentTime())
+ return;
+ this.nextItem = null;
+ if (typeof this.renderer.cancelTrackGainChange === 'function')
+ this.renderer.cancelTrackGainChange();
+ this.renderer.truncateScheduleAt(next.base);
+ this.renderer.markStreamComplete();
+ this.disposeItemAsync(next).catch((error) => {
+ console.debug('Audio player: the upcoming track of the replaced queue could not be released.', error);
+ });
+ }
+
/**
* Starts, or resumes, audible playback.
* @returns {Promise} A promise that completes when the renderer is running.
diff --git a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-queue.js b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-queue.js
new file mode 100644
index 00000000..70601b6f
--- /dev/null
+++ b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player-queue.js
@@ -0,0 +1,1719 @@
+/**
+ * Queue model, play context resolution and client storage of the audio player.
+ *
+ * The player owns exactly one queue. This module defines that queue as a value object ({@link LuminaAudioPlayer.AudioQueue}),
+ * the service that builds a queue from a play context through the web endpoints of the music pages
+ * ({@link LuminaAudioPlayer.QueueContextService}), and the sampler that draws randomized tracks for a shuffle scope
+ * ({@link LuminaAudioPlayer.ShuffleSource}).
+ *
+ * Play contexts and the web endpoints used for each
+ * --------------------------------------------------
+ * The pages hand the player a play descriptor, per LuminaAudioPlayer.createPlayDescriptor. A descriptor that carries an
+ * explicit queue is used as is: the page already knows the ordered tracks of its context. A descriptor that names only
+ * a context is resolved here:
+ * - Album context (libraryId, artistId, albumId, without a trackId; optionally with a queue):
+ * WebRoutes.Music.GET_ALBUM_TRACKS ("api-get-tracks") returns the ordered tracks of the release. The endpoint orders
+ * them by disc number and then track number, which is the playback order of the release.
+ * - Artist context (libraryId, artistId, without an albumId or trackId; optionally with a queue):
+ * WebRoutes.Music.GET_ARTIST_ALBUMS ("api-get-albums") returns the releases of the artist, which this module orders like
+ * the artist page: primary release type group in releaseTypeOrder, then release year, title and Id. Then
+ * WebRoutes.Music.GET_ALBUM_TRACKS returns the ordered tracks of a release. The queue is every release in that order,
+ * with each release's tracks in disc and track number order. All releases are fetched before playback starts, with a
+ * small concurrency bound so a prolific artist does not turn into hundreds of sequential requests.
+ * - Track context (libraryId, trackId):
+ * The descriptor itself is the only item. A track page does not load the album or the discography around it.
+ *
+ * The autoplay continuation at the end of an album or an artist uses the same endpoints:
+ * - After an album, the remaining releases of the artist, in the release order this module applies (primary release
+ * type group, then release year, title and Id). When those are exhausted, the next artists of the library, in the
+ * artist order of GET_ARTISTS ("api-get-artists"), one artist at a time, each with all of its releases and tracks.
+ * - After an artist, the next artists of the library, one at a time.
+ * A continuation batch is never built for a track context or for an explicit queue, and it is dropped as soon as the user
+ * queues an explicit play next item.
+ *
+ * Shuffle scopes
+ * --------------
+ * Shuffle is offered per release, per artist and per library. It does not materialize a whole category: it appends a
+ * batch of {@link SHUFFLE_BATCH_SIZE} randomized tracks and, while the queue approaches the end of that batch, appends
+ * another batch of the same category. The release and artist scopes only load the lightweight release metadata of the
+ * category and prefetch the track lists of a small, bounded number of releases in parallel, never the whole category.
+ * The library scope only loads the lightweight artist metadata and the releases of one artist at a time, so choosing
+ * shuffle on an entire library never puts every track of the library into the queue and never fetches every track of the
+ * library at once.
+ *
+ * Lifetime
+ * --------
+ * The queue lives only in memory for the current page. A full page load creates a new player with an empty queue and the
+ * bar hidden. An in-place navigation does not recreate the player, so the queue survives those swaps.
+ */
+(function (LuminaAudioPlayer) {
+ 'use strict';
+
+ /**
+ * The repeat modes of the queue.
+ * @readonly
+ * @enum {string}
+ */
+ LuminaAudioPlayer.QueueRepeatMode = Object.freeze({
+ // Playback stops at the end of the queue.
+ OFF: 'off',
+ // Playback wraps to the first entry at the end of the queue.
+ ALL: 'all',
+ // The current entry is played again when it ends.
+ ONE: 'one'
+ });
+
+ /**
+ * The categories a shuffle can draw from.
+ * @readonly
+ * @enum {string}
+ */
+ LuminaAudioPlayer.QueueShuffleScope = Object.freeze({
+ // The tracks of the release that is playing.
+ RELEASE: 'release',
+ // All tracks of all releases of the artist that is playing.
+ ARTIST: 'artist',
+ // All tracks of all releases of all artists of the library.
+ LIBRARY: 'library'
+ });
+
+ /**
+ * The kinds of play context a queue can belong to.
+ * @readonly
+ * @enum {string}
+ */
+ LuminaAudioPlayer.PlayContextKind = Object.freeze({
+ ALBUM: 'album',
+ ARTIST: 'artist',
+ TRACK: 'track',
+ QUEUE: 'queue'
+ });
+
+ /**
+ * The number of randomized tracks a shuffle appends at a time, so that a large category is never materialized as one
+ * queue.
+ * @readonly
+ * @type {number}
+ */
+ const SHUFFLE_BATCH_SIZE = 100;
+
+ /**
+ * The number of entries that may remain after the current one before the queue requests the next shuffle batch. It is
+ * the look ahead that hides the fetch behind the last ten tracks of the previous batch.
+ * @readonly
+ * @type {number}
+ */
+ const SHUFFLE_LOOKAHEAD = 10;
+
+ /**
+ * The number of release track lists a shuffle batch fetches at the same time. A batch of 100 tracks spans about nine
+ * releases, so resolving their track lists concurrently removes most of the sequential wait before the batch is ready.
+ * @readonly
+ * @type {number}
+ */
+ const SHUFFLE_PREFETCH_CONCURRENCY = 4;
+
+ /**
+ * The number of history entries the queue keeps, so a very long session cannot grow the queue without bound.
+ * @readonly
+ * @type {number}
+ */
+ const MAX_HISTORY_ENTRIES = 500;
+
+ /**
+ * The highest entry sequence the identity format accepts. It stays one below the largest safe integer, so the next
+ * generated identity remains a safe integer.
+ * @readonly
+ * @type {number}
+ */
+ const MAX_ENTRY_SEQUENCE = Number.MAX_SAFE_INTEGER - 1;
+
+ /**
+ * The number of pages of a paginated endpoint the queue builder follows. It is a safety bound for a server that reports
+ * an inconsistent page count, not a product limit.
+ * @readonly
+ * @type {number}
+ */
+ const MAX_PAGES = 1000;
+
+ /**
+ * The number of release track lists the queue builder requests at the same time when it builds a whole artist, so a
+ * prolific artist does not turn into hundreds of sequential requests, while the server is not flooded either.
+ * @readonly
+ * @type {number}
+ */
+ const ALBUM_FETCH_CONCURRENCY = 4;
+
+ /**
+ * The maximum number of artist release lists kept by the queue context service. The cache is an LRU, so a long
+ * library shuffle keeps the most recently used artists instead of every artist it ever visited.
+ * @readonly
+ * @type {number}
+ */
+ const RELEASE_CACHE_MAX_ENTRIES = 64;
+
+ /**
+ * The maximum number of library artist lists kept by the queue context service. A browser session normally touches a
+ * handful of libraries, so a small LRU is enough while it still bounds a long session.
+ * @readonly
+ * @type {number}
+ */
+ const ARTIST_CACHE_MAX_ENTRIES = 8;
+
+ /**
+ * The order of the release type groups of an artist page, from the most common to the least common. It mirrors the
+ * releaseTypeOrder of the artist page, because the queue plays the discography in the order the page displays it.
+ * @readonly
+ * @type {ReadonlyArray}
+ */
+ const RELEASE_TYPE_ORDER = Object.freeze([
+ 'Album', 'Compilation', 'Ep', 'Live', 'Remix', 'Single', 'Soundtrack', 'Broadcast', 'AudioDrama', 'AudioBook',
+ 'Demo', 'DjMix', 'FieldRecording', 'Interview', 'Mixtape', 'SpokenWord', 'Other'
+ ]);
+
+ /**
+ * Gets the primary release type group of a release row, falling back to Other when the endpoint carries no usable type.
+ * @param {Object} release - The release row.
+ * @returns {string} The primary release type.
+ */
+ function getPrimaryReleaseType(release) {
+ const releaseTypes = release && release.releaseTypes;
+ const primary = Array.isArray(releaseTypes) && releaseTypes.length > 0
+ ? releaseTypes[0]
+ : (typeof releaseTypes === 'string' ? releaseTypes : '');
+ return typeof primary === 'string' && primary !== '' ? primary : 'Other';
+ }
+
+ /**
+ * Orders release rows like the artist page: primary release type group first, then release year, title and Id.
+ *
+ * The release endpoint orders by album title, which is not the order an artist's discography is presented or played in.
+ * The artist page groups releases by their first release type in its releaseTypeOrder and sorts each group by release
+ * year. The queue applies the same order here, so an artist context and its autoplay continuation follow the page. A
+ * release without a year sorts first within its group, and the title and Id keep the order deterministic for a year
+ * shared by several releases.
+ * @param {Object} left - The first release row.
+ * @param {Object} right - The second release row.
+ * @returns {number} The comparator result.
+ */
+ function compareReleaseRows(left, right) {
+ const leftType = getPrimaryReleaseType(left);
+ const rightType = getPrimaryReleaseType(right);
+ const leftTypeIndex = RELEASE_TYPE_ORDER.indexOf(leftType);
+ const rightTypeIndex = RELEASE_TYPE_ORDER.indexOf(rightType);
+ const leftGroup = leftTypeIndex >= 0 ? leftTypeIndex : RELEASE_TYPE_ORDER.length;
+ const rightGroup = rightTypeIndex >= 0 ? rightTypeIndex : RELEASE_TYPE_ORDER.length;
+ if (leftGroup !== rightGroup)
+ return leftGroup - rightGroup;
+ const leftYear = Number.isFinite(Number(left && left.releaseYear)) ? Number(left.releaseYear) : 0;
+ const rightYear = Number.isFinite(Number(right && right.releaseYear)) ? Number(right.releaseYear) : 0;
+ if (leftYear !== rightYear)
+ return leftYear - rightYear;
+ const leftTitle = String((left && left.title) || '');
+ const rightTitle = String((right && right.title) || '');
+ if (leftTitle !== rightTitle)
+ return leftTitle < rightTitle ? -1 : 1;
+ const leftId = String((left && left.id) || '');
+ const rightId = String((right && right.id) || '');
+ return leftId === rightId ? 0 : (leftId < rightId ? -1 : 1);
+ }
+
+ /**
+ * Shuffles a copy of a list with the Fisher-Yates algorithm.
+ * @template T
+ * @param {Array} items - The items to shuffle.
+ * @returns {Array} A new, shuffled list; the input is never mutated.
+ */
+ function shuffleCopy(items) {
+ const result = Array.isArray(items) ? [...items] : [];
+ for (let index = result.length - 1; index > 0; index--) {
+ const swapIndex = Math.floor(Math.random() * (index + 1));
+ const value = result[index];
+ result[index] = result[swapIndex];
+ result[swapIndex] = value;
+ }
+ return result;
+ }
+
+ /**
+ * Reads a value from an insertion ordered cache and marks it as the most recently used.
+ * @param {Map} cache - The cache to read.
+ * @param {string} key - The cache key.
+ * @returns {*|null} The cached value, or null when the key is absent.
+ */
+ function readCacheEntry(cache, key) {
+ if (!cache.has(key))
+ return null;
+ const value = cache.get(key);
+ cache.delete(key);
+ cache.set(key, value);
+ return value;
+ }
+
+ /**
+ * Writes a value to an insertion ordered cache and evicts the least recently used entries above its bound.
+ * @param {Map} cache - The cache to write.
+ * @param {string} key - The cache key.
+ * @param {*} value - The value to cache.
+ * @param {number} maximum - The maximum number of entries the cache may hold.
+ */
+ function writeCacheEntry(cache, key, value, maximum) {
+ if (cache.has(key))
+ cache.delete(key);
+ cache.set(key, value);
+ while (cache.size > maximum) {
+ const oldest = cache.keys().next().value;
+ if (oldest === undefined)
+ break;
+ cache.delete(oldest);
+ }
+ }
+
+ /**
+ * Gets the identity a track is deduplicated by inside a shuffled queue.
+ * @param {Object} descriptor - The play descriptor of the track.
+ * @returns {string} The track identity, or an empty string when the descriptor carries no track.
+ */
+ function getTrackIdentity(descriptor) {
+ return descriptor && descriptor.trackId ? descriptor.trackId.toLowerCase() : '';
+ }
+
+ /**
+ * Limits a list of promises to a maximum number of concurrent operations.
+ * @template T, R
+ * @param {Array} items - The items to process.
+ * @param {number} limit - The maximum number of operations that may run at the same time.
+ * @param {Function} operation - The operation, receiving an item and returning a Promise.
+ * @returns {Promise>} The results, in the order of the input.
+ */
+ async function mapWithConcurrencyAsync(items, limit, operation) {
+ const results = new Array(items.length);
+ let nextIndex = 0;
+ const workers = [];
+ const workerCount = Math.max(1, Math.min(limit, items.length));
+ for (let worker = 0; worker < workerCount; worker++) {
+ workers.push((async () => {
+ while (nextIndex < items.length) {
+ const index = nextIndex;
+ nextIndex += 1;
+ results[index] = await operation(items[index], index);
+ }
+ })());
+ }
+ await Promise.all(workers);
+ return results;
+ }
+
+ /**
+ * Gets the origin the queue endpoints are resolved against. The page origin is used in a browser; a fixed local
+ * origin keeps the URL checks usable in a host without a DOM.
+ * @returns {string} The base origin.
+ */
+ function getBaseOrigin() {
+ return typeof window !== 'undefined' && window.location && window.location.origin
+ ? window.location.origin
+ : 'http://localhost';
+ }
+
+ /**
+ * Throws the typed error that stops a queue build which the session redirect already owns.
+ * @returns {never} Never returns; it always throws.
+ */
+ function throwSessionExpired() {
+ throw new LuminaAudioPlayer.PlayerError(
+ LuminaAudioPlayer.PlayerErrorCode.QUEUE_LOAD_FAILED,
+ 'The session expired while the play context was loaded.',
+ { reason: LuminaAudioPlayer.PlayerErrorReason.SESSION_EXPIRED });
+ }
+
+ /**
+ * The queue of the player: ordered entries with an identity per occurrence, the cursor, the navigation history, the
+ * repeat and shuffle modes, the play context, and the continuation state.
+ *
+ * Every traversal is derived from the entries and the cursor, so a queue can never describe two different tracks at
+ * the same time. A queue entry keeps its identity across an advance, which is what lets a gapless handoff and a normal
+ * continuation share the same commit.
+ */
+ class AudioQueue {
+ /**
+ * Creates an instance of AudioQueue.
+ */
+ constructor() {
+ /**
+ * The ordered entries of the queue, each { entryId, descriptor, source }. The source is one of 'context',
+ * 'manual', 'queue', 'shuffle' or 'continuation'.
+ * @type {Array