mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +00:00
Fetch media player image from websocket (#1137)
This commit is contained in:
parent
3e90db5fa3
commit
9fc3d9d019
@ -238,37 +238,25 @@ class HaMediaPlayerCard extends
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
playerObjChanged(playerObj) {
|
playerObjChanged(playerObj, oldPlayerObj) {
|
||||||
var picture = playerObj.stateObj.attributes.entity_picture;
|
const picture = playerObj.stateObj.attributes.entity_picture;
|
||||||
var dummy;
|
const oldPicture = oldPlayerObj && oldPlayerObj.stateObj.attributes.entity_picture;
|
||||||
if (picture) {
|
|
||||||
dummy = document.createElement('IMG');
|
if (picture !== oldPicture && !picture) {
|
||||||
dummy.onload = () => {
|
|
||||||
this.$.cover.style.backgroundImage = 'url(' + picture + ')';
|
|
||||||
dummy.onerror = dummy.onload = null;
|
|
||||||
dummy.src = '';
|
|
||||||
dummy = null;
|
|
||||||
};
|
|
||||||
dummy.onerror = () => {
|
|
||||||
this.$.cover.style.backgroundImage = '';
|
|
||||||
this.$.cover.parentElement.classList.add('no-cover');
|
|
||||||
dummy.onerror = dummy.onload = null;
|
|
||||||
dummy.src = '';
|
|
||||||
dummy = null;
|
|
||||||
};
|
|
||||||
if (this._timeout_id) {
|
|
||||||
clearTimeout(this._timeout_id);
|
|
||||||
}
|
|
||||||
this._timeout_id = setTimeout(() => {
|
|
||||||
if (dummy) {
|
|
||||||
// Background load still inflight. Clear real image.
|
|
||||||
this.$.cover.style.backgroundImage = '';
|
|
||||||
}
|
|
||||||
this._timeout_id = null;
|
|
||||||
}, 5000);
|
|
||||||
dummy.src = picture;
|
|
||||||
} else {
|
|
||||||
this.$.cover.style.backgroundImage = '';
|
this.$.cover.style.backgroundImage = '';
|
||||||
|
} else if (picture !== oldPicture) {
|
||||||
|
// We have a new picture url
|
||||||
|
this.hass.connection.sendMessagePromise({
|
||||||
|
type: 'media_player_thumbnail',
|
||||||
|
entity_id: playerObj.stateObj.entity_id,
|
||||||
|
}).then((resp) => {
|
||||||
|
if (resp.success) {
|
||||||
|
this.$.cover.style.backgroundImage = `url(data:${resp.result.content_type};base64,${resp.result.content})`;
|
||||||
|
} else {
|
||||||
|
this.$.cover.style.backgroundImage = '';
|
||||||
|
this.$.cover.parentElement.classList.add('no-cover');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerObj.isPlaying && playerObj.showProgress) {
|
if (playerObj.isPlaying && playerObj.showProgress) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user