From 1ed65437b815ad1d90617e274c9be8602895682b Mon Sep 17 00:00:00 2001 From: "Glenn Vandeuren (aka Iondependent)" Date: Mon, 23 Dec 2024 17:33:46 +0100 Subject: [PATCH] Update ha-media-player-browse.ts --- .../media-player/ha-media-player-browse.ts | 157 +++++++++++------- 1 file changed, 98 insertions(+), 59 deletions(-) diff --git a/src/components/media-player/ha-media-player-browse.ts b/src/components/media-player/ha-media-player-browse.ts index 5c20cf4a0b63..b0024e6acd62 100644 --- a/src/components/media-player/ha-media-player-browse.ts +++ b/src/components/media-player/ha-media-player-browse.ts @@ -31,7 +31,10 @@ import { BROWSER_PLAYER, MediaClassBrowserSettings, } from "../../data/media-player"; -import { browseLocalMediaPlayer } from "../../data/media_source"; +import { + browseLocalMediaPlayer, + resolveMediaSource, +} from "../../data/media_source"; import { isTTSMediaSource } from "../../data/tts"; import { showAlertDialog } from "../../dialogs/generic/show-dialog-box"; import { haStyle } from "../../resources/styles"; @@ -81,7 +84,7 @@ export class HaMediaPlayerBrowse extends LitElement { @property() public action: MediaPlayerBrowseAction = "play"; - @property({ attribute: false }) + @property({ reflect: true, attribute: "preferred-layout" }) public preferredLayout: MediaPlayerLayoutType = "auto"; @property({ type: Boolean }) public dialog = false; @@ -94,6 +97,8 @@ export class HaMediaPlayerBrowse extends LitElement { // @todo Consider reworking to eliminate need for attribute since it is manipulated internally @property({ type: Boolean, reflect: true }) public scrolled = false; + @property({ attribute: false }) public backgroundImage: string | undefined; + @state() private _error?: { message: string; code: string }; @state() private _parentItem?: MediaPlayerItem; @@ -340,10 +345,8 @@ export class HaMediaPlayerBrowse extends LitElement { : MediaClassBrowserSettings.directory; const backgroundImage = currentItem.thumbnail - ? this._getThumbnailURLorBase64(currentItem.thumbnail).then( - (value) => `url(${value})` - ) - : "none"; + ? this._getThumbnailURLorBase64(currentItem.thumbnail) + : undefined; return html` ${ @@ -359,13 +362,14 @@ export class HaMediaPlayerBrowse extends LitElement {
${currentItem.thumbnail ? html` -
+
+ ${currentItem.title + ${this.narrow && currentItem?.can_play ? html` { const backgroundImage = child.thumbnail - ? this._getThumbnailURLorBase64(child.thumbnail).then( - (value) => `url(${value})` - ) - : "none"; + ? this._getThumbnailURLorBase64(child.thumbnail) + : child.media_class === "image" + ? resolveMediaSource(this.hass, child.media_content_id).then( + ({ url }) => url + ) + : undefined; return html`
- ${child.thumbnail + ${child.thumbnail || child.media_class === "image" ? html` -
+ src=${until(backgroundImage, "")} + loading="lazy" + /> ` : html`
@@ -618,12 +626,16 @@ export class HaMediaPlayerBrowse extends LitElement { const currentItem = this._currentItem; const mediaClass = MediaClassBrowserSettings[currentItem!.media_class]; - const backgroundImage = - mediaClass.show_list_images && child.thumbnail - ? this._getThumbnailURLorBase64(child.thumbnail).then( - (value) => `url(${value})` - ) - : "none"; + let backgroundImage; + if (mediaClass.show_list_images) { + backgroundImage = child.thumbnail + ? this._getThumbnailURLorBase64(child.thumbnail) + : child.media_class === "image" + ? resolveMediaSource(this.hass, child.media_content_id).then( + ({ url }) => url + ) + : undefined; + } return html` - ${backgroundImage === "none" && !child.can_play + ${backgroundImage === undefined ? html`` + .path=${MediaClassBrowserSettings[ + child.media_class === "directory" + ? child.children_media_class || child.media_class + : child.media_class + ].icon} + slot="graphic" + > + ${child.can_play + ? html`` + : nothing}` : html`
+ ${child.title} ${child.can_play ? html`