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..b20d66589061 100644 --- a/src/components/media-player/ha-media-player-browse.ts +++ b/src/components/media-player/ha-media-player-browse.ts @@ -36,7 +36,10 @@ import { MediaPlayerBrowseAction, MediaPlayerLayoutType, } 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"; @@ -86,7 +89,8 @@ export class HaMediaPlayerBrowse extends LitElement { @property() public action: MediaPlayerBrowseAction = "play"; - @property() public preferredLayout: MediaPlayerLayoutType = "auto"; + @property({ reflect: true, attribute: "preferred-layout" }) + public preferredLayout: MediaPlayerLayoutType = "auto"; @property({ type: Boolean }) public dialog = false; @@ -98,6 +102,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; @@ -344,10 +350,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 +367,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`
@@ -622,12 +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 - ? 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 && !child.can_play ? html`` - : html`
- ${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 { @@ -1072,27 +1120,27 @@ export class HaMediaPlayerBrowse extends LitElement { } ha-card .image { - border-radius: 3px 3px 0 0; + border-radius: var(--ha-card-border-radius, 12px); + padding: 4px; + box-sizing: border-box; } - .image { - position: absolute; - top: 0; - right: 0; - left: 0; - bottom: 0; - background-size: cover; - background-repeat: no-repeat; - background-position: center; + :host([preferred-layout="list"]) img { + height: 56px; + width: 56px; } - .centered-image { - margin: 0 8px; - background-size: contain; + .image { + max-height: 173px; + width: 100%; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); } .brand-image { - background-size: 40%; + width: 40%; } .children ha-card .icon-holder { @@ -1163,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; @@ -1174,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; @@ -1319,7 +1369,6 @@ export class HaMediaPlayerBrowse extends LitElement { lit-virtualizer { height: 100%; - overflow: overlay !important; contain: size layout !important; }