From 20f7b085bffe4609b3f29b3416a40706f13dc3e8 Mon Sep 17 00:00:00 2001
From: Amit <91756648+pathofleastresistor@users.noreply.github.com>
Date: Sun, 21 Jan 2024 11:44:35 -0800
Subject: [PATCH] Add a play button when browing to playable element
* Add a play button when browing to playable element
---
polr-ytube-media-card.js | 29 ++++++++++++++++++++++++
src/elements/polr-ytube-browser.ts | 36 ++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/polr-ytube-media-card.js b/polr-ytube-media-card.js
index 81e58e4..c54a7d7 100644
--- a/polr-ytube-media-card.js
+++ b/polr-ytube-media-card.js
@@ -4699,6 +4699,7 @@ let PoLRYTubeBrowser = class PoLRYTubeBrowser extends s$1 {
return x `
${this._renderSearch()} ${this._renderNavigation()}
+ ${this._renderPlay()}
`;
}
+ _renderPlay() {
+ const element = this._browseHistory[this._browseHistory.length - 1];
+ console.log(element);
+ if (element === null || element === void 0 ? void 0 : element.can_play) {
+ return x `
+
+ ${element.title}
+ this.hass.callService("media_player", "play_media", {
+ entity_id: this.entity["entity_id"],
+ media_content_id: element.media_content_id,
+ media_content_type: element.media_content_type,
+ })}
+ >
+ Play
+
+
+ `;
+ }
+ }
_handleSearchInput(ev) {
if (ev.keyCode == 13) {
this._search();
@@ -4930,6 +4953,12 @@ let PoLRYTubeBrowser = class PoLRYTubeBrowser extends s$1 {
gap: 4px;
}
+ .playable_result {
+ display: inline-flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
polr-ytube-list {
overflow: auto;
}
diff --git a/src/elements/polr-ytube-browser.ts b/src/elements/polr-ytube-browser.ts
index b6be619..b234ae9 100644
--- a/src/elements/polr-ytube-browser.ts
+++ b/src/elements/polr-ytube-browser.ts
@@ -47,6 +47,7 @@ export class PoLRYTubeBrowser extends LitElement {
return html`
${this._renderSearch()} ${this._renderNavigation()}
+ ${this._renderPlay()}
+ ${element.title}
+
+ this.hass.callService(
+ "media_player",
+ "play_media",
+ {
+ entity_id: this.entity["entity_id"],
+ media_content_id: element.media_content_id,
+ media_content_type:
+ element.media_content_type,
+ }
+ )}
+ >
+ Play
+
+
+ `;
+ }
+ }
+
private _handleSearchInput(ev) {
if (ev.keyCode == 13) {
this._search();
@@ -304,6 +334,12 @@ export class PoLRYTubeBrowser extends LitElement {
gap: 4px;
}
+ .playable_result {
+ display: inline-flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
polr-ytube-list {
overflow: auto;
}