diff --git a/src/facets/themes/albums-app/browser/element.css b/src/facets/themes/albums-app/browser/element.css index aada84ae..9e93ef14 100644 --- a/src/facets/themes/albums-app/browser/element.css +++ b/src/facets/themes/albums-app/browser/element.css @@ -98,6 +98,7 @@ a.da-titlebar__btn { font-size: 0.75rem; font-weight: 600; margin-right: 0.25rem; + white-space: nowrap; } /* Shell */ @@ -248,9 +249,34 @@ a.da-titlebar__btn { flex-shrink: 0; height: 2.25rem; overflow: hidden; + position: relative; width: 2.25rem; } +.da-mini__art-loading { + align-items: center; + background: rgb(0 0 0 / 0.45); + bottom: 0; + color: var(--da-text); + display: flex; + justify-content: center; + left: 0; + position: absolute; + right: 0; + top: 0; +} + +.da-mini__art-loading i { + animation: da-mini-spin 1.6s linear infinite; + font-size: 1.25rem; +} + +@keyframes da-mini-spin { + to { + transform: rotate(360deg); + } +} + .da-mini__art img { display: block; height: 100%; @@ -367,6 +393,10 @@ a.da-titlebar__btn { width: 2.25rem; } +.da-mini__play--error { + background: var(--da-accent); +} + .da-mini__play i { font-size: 1.5rem; line-height: 1; diff --git a/src/facets/themes/albums-app/browser/element.js b/src/facets/themes/albums-app/browser/element.js index 330e0b6f..2082c6a2 100644 --- a/src/facets/themes/albums-app/browser/element.js +++ b/src/facets/themes/albums-app/browser/element.js @@ -251,6 +251,15 @@ class Browser extends DiffuseElement { #history = signal(/** @type {View[]} */ ([])); #future = signal(/** @type {View[]} */ ([])); + // Mini player audio state — loading is debounced so quick track + // switches don't flash the spinner + /** @type {ReturnType | undefined} */ + #isLoadingTimeout = undefined; + + #isLoading = signal(false); + + #audioError = signal(false); + // Cover art cache (albums, artists and playlist thumbnails share it) /** @type {Map} */ #coverArtCache = new Map(); @@ -638,6 +647,30 @@ class Browser extends DiffuseElement { }); }); + // Mini player loading / error state. The loading spinner only + // surfaces after a short delay so fast track switches don't flash + // it; errors surface immediately (pattern from blur / winamp). + this.effect(() => { + const now = !!this.$controller.value?.$queue.value?.now(); + const loadingState = this.$controller.value?.audio()?.loadingState(); + const isError = now && typeof loadingState === "object" && + loadingState !== null && "error" in loadingState; + const isLoading = now && !isError && loadingState !== "loaded"; + + if (this.#isLoadingTimeout) clearTimeout(this.#isLoadingTimeout); + + if (isLoading) { + this.#isLoadingTimeout = setTimeout( + () => this.#isLoading.value = true, + 2000, + ); + } else { + this.#isLoading.value = false; + } + + this.#audioError.value = isError; + }); + // Re-attach the representative track to a restored detail view once // the library is available; fall back to the overview when the // album / artist no longer exists @@ -681,6 +714,10 @@ class Browser extends DiffuseElement { this.#resizeObserver?.disconnect(); this.#resizeObserver = undefined; this.#observedPanel = null; + if (this.#isLoadingTimeout) { + clearTimeout(this.#isLoadingTimeout); + this.#isLoadingTimeout = undefined; + } } // HELPERS @@ -981,6 +1018,19 @@ class Browser extends DiffuseElement { } }; + /** Retry the current track after a load error, resuming at its position. */ + reload = () => { + const audioId = this.$controller.value?.$queue.value?.now()?.id; + if (audioId) { + const progress = this.$controller.value?.audio()?.progress(); + this.$controller.value?.$audio.value?.reload({ + audioId, + play: true, + progress, + }); + } + }; + next = () => { this.$controller.value?.$queue.value?.shift(); }; @@ -1680,6 +1730,9 @@ class Browser extends DiffuseElement { this.#fetchAlbumArt(albumKey, track); } + const isLoading = this.#isLoading.value; + const isError = this.#audioError.value; + return html`
@@ -1691,6 +1744,13 @@ class Browser extends DiffuseElement {
`} + ${isLoading + ? html` +
+ +
+ ` + : nothing}
${track?.tags?.title ?? "Not playing"} @@ -1720,8 +1780,13 @@ class Browser extends DiffuseElement { -