From fdab99c56dd019952287b6b9942153f1310397dc Mon Sep 17 00:00:00 2001 From: VandeurenGlenn Date: Fri, 4 Oct 2024 18:21:12 +0200 Subject: [PATCH 1/3] Initial improve thumbnail performance --- .../ha-selector/ha-selector-media.ts | 18 ++++++---- .../media-player/ha-media-player-browse.ts | 35 ++++++++----------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/components/ha-selector/ha-selector-media.ts b/src/components/ha-selector/ha-selector-media.ts index 86fa91335d48..3e1081f45b68 100644 --- a/src/components/ha-selector/ha-selector-media.ts +++ b/src/components/ha-selector/ha-selector-media.ts @@ -124,19 +124,23 @@ export class HaMediaSelector extends LitElement { > ${this.value?.metadata?.thumbnail ? html` -
+ })} image" + src=${this._thumbnailUrl ?? ""} + /> ` : html`
diff --git a/src/components/media-player/ha-media-player-browse.ts b/src/components/media-player/ha-media-player-browse.ts index b0ed61efe5f1..fa2a53188b9e 100644 --- a/src/components/media-player/ha-media-player-browse.ts +++ b/src/components/media-player/ha-media-player-browse.ts @@ -344,10 +344,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` ${ @@ -363,13 +361,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) + : undefined; return html`
@@ -624,10 +621,8 @@ export class HaMediaPlayerBrowse extends LitElement { const backgroundImage = mediaClass.show_list_images && child.thumbnail - ? this._getThumbnailURLorBase64(child.thumbnail).then( - (value) => `url(${value})` - ) - : "none"; + ? this._getThumbnailURLorBase64(child.thumbnail) + : undefined; return html` - ${backgroundImage === "none" && !child.can_play + ${backgroundImage === undefined && !child.can_play ? html` Date: Fri, 11 Oct 2024 11:31:57 +0200 Subject: [PATCH 2/3] Fix css rules & add some padding around images --- .../media-player/ha-media-player-browse.ts | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/components/media-player/ha-media-player-browse.ts b/src/components/media-player/ha-media-player-browse.ts index fa2a53188b9e..3106fef09afc 100644 --- a/src/components/media-player/ha-media-player-browse.ts +++ b/src/components/media-player/ha-media-player-browse.ts @@ -566,15 +566,16 @@ export class HaMediaPlayerBrowse extends LitElement {
${child.thumbnail ? html` -
+ src=${until(backgroundImage, "")} + /> ` : html`
@@ -644,9 +645,13 @@ export class HaMediaPlayerBrowse extends LitElement { graphic: true, thumbnail: mediaClass.show_list_images === true, })} - style="background-image: ${until(backgroundImage, "")}" slot="graphic" > + ${child.title} ${child.can_play ? html` ${currentItem.title ${this.narrow && currentItem?.can_play @@ -481,7 +487,6 @@ export class HaMediaPlayerBrowse extends LitElement { childrenMediaClass.layout === "grid") ? html` { const backgroundImage = child.thumbnail ? this._getThumbnailURLorBase64(child.thumbnail) - : undefined; + : 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` ${child.title} ` : html` @@ -620,10 +631,16 @@ export class HaMediaPlayerBrowse extends LitElement { const currentItem = this._currentItem; const mediaClass = MediaClassBrowserSettings[currentItem!.media_class]; - const backgroundImage = - mediaClass.show_list_images && child.thumbnail + let backgroundImage; + if (mediaClass.show_list_images) { + backgroundImage = child.thumbnail ? this._getThumbnailURLorBase64(child.thumbnail) - : undefined; + : child.media_class === "image" + ? resolveMediaSource(this.hass, child.media_content_id).then( + ({ url }) => url + ) + : undefined; + } return html` ` - : html`
- ${child.title} - ${child.can_play - ? html`` - : nothing} -
`} + : backgroundImage === undefined + ? html` + ${child.can_play + ? html`` + : nothing}` + : html`
+ ${child.title} + ${child.can_play + ? html`` + : nothing} +
`} ${child.title}
`; @@ -909,10 +948,17 @@ export class HaMediaPlayerBrowse extends LitElement { .content { overflow-y: auto; - box-sizing: border-box; height: 100%; } + :host([preferred-layout="list"]) .content { + align-items: center; + display: flex; + flex-direction: column; + box-sizing: border-box; + padding: 4px; + } + /* HEADER */ .header { @@ -1016,6 +1062,8 @@ export class HaMediaPlayerBrowse extends LitElement { --mdc-list-item-graphic-margin: 0; --mdc-theme-text-icon-on-background: var(--secondary-text-color); margin-top: 10px; + width: 100%; + max-width: 1120px; } mwc-list li:last-child { @@ -1077,8 +1125,13 @@ export class HaMediaPlayerBrowse extends LitElement { box-sizing: border-box; } + :host([preferred-layout="list"]) img { + height: 56px; + width: 56px; + } + .image { - aspect-ratio: 1 / 1; + max-height: 173px; width: 100%; position: absolute; top: 50%; @@ -1158,10 +1211,8 @@ export class HaMediaPlayerBrowse extends LitElement { padding-left: 16px; } - mwc-list-item .graphic { - background-size: contain; - background-repeat: no-repeat; - background-position: center; + mwc-list-item .graphic, + mwc-list-item .graphic img { border-radius: 2px; display: flex; align-content: center; @@ -1169,6 +1220,10 @@ export class HaMediaPlayerBrowse extends LitElement { line-height: initial; } + mwc-list-item .graphic img { + position: absolute; + } + mwc-list-item .graphic .play { opacity: 0; transition: all 0.5s; @@ -1314,7 +1369,6 @@ export class HaMediaPlayerBrowse extends LitElement { lit-virtualizer { height: 100%; - overflow: overlay !important; contain: size layout !important; }