mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Add support for buffering state in media browser (#15459)
This commit is contained in:
parent
e91a477b8b
commit
1ab1cf0fab
@ -73,7 +73,9 @@ export interface MediaPlayerEntity extends HassEntityBase {
|
|||||||
| "off"
|
| "off"
|
||||||
| "on"
|
| "on"
|
||||||
| "unavailable"
|
| "unavailable"
|
||||||
| "unknown";
|
| "unknown"
|
||||||
|
| "standby"
|
||||||
|
| "buffering";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum MediaPlayerEntityFeature {
|
export const enum MediaPlayerEntityFeature {
|
||||||
|
@ -70,10 +70,6 @@ export class BrowserMediaPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get isPlaying(): boolean {
|
|
||||||
return this.buffering || (!this.player.paused && !this.player.ended);
|
|
||||||
}
|
|
||||||
|
|
||||||
static idleStateObj(): MediaPlayerEntity {
|
static idleStateObj(): MediaPlayerEntity {
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
return {
|
return {
|
||||||
@ -88,9 +84,13 @@ export class BrowserMediaPlayer {
|
|||||||
|
|
||||||
toStateObj(): MediaPlayerEntity {
|
toStateObj(): MediaPlayerEntity {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
|
||||||
const base = BrowserMediaPlayer.idleStateObj();
|
const stateObj = BrowserMediaPlayer.idleStateObj();
|
||||||
base.state = this.isPlaying ? "playing" : "paused";
|
stateObj.state = this.buffering
|
||||||
base.attributes = {
|
? "buffering"
|
||||||
|
: this.player.paused || this.player.ended
|
||||||
|
? "paused"
|
||||||
|
: "playing";
|
||||||
|
stateObj.attributes = {
|
||||||
media_title: this.item.title,
|
media_title: this.item.title,
|
||||||
entity_picture: this.item.thumbnail,
|
entity_picture: this.item.thumbnail,
|
||||||
volume_level: this.player.volume,
|
volume_level: this.player.volume,
|
||||||
@ -103,10 +103,10 @@ export class BrowserMediaPlayer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (this.player.duration) {
|
if (this.player.duration) {
|
||||||
base.attributes.media_duration = this.player.duration;
|
stateObj.attributes.media_duration = this.player.duration;
|
||||||
base.attributes.media_position = this.player.currentTime;
|
stateObj.attributes.media_position = this.player.currentTime;
|
||||||
base.attributes.media_position_updated_at = base.last_updated;
|
stateObj.attributes.media_position_updated_at = stateObj.last_updated;
|
||||||
}
|
}
|
||||||
return base;
|
return stateObj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ export class BarMediaPlayer extends SubscribeMixin(LitElement) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="controls-progress">
|
<div class="controls-progress">
|
||||||
${this._browserPlayer?.buffering
|
${stateObj.state === "buffering"
|
||||||
? html` <ha-circular-progress active></ha-circular-progress> `
|
? html` <ha-circular-progress active></ha-circular-progress> `
|
||||||
: html`
|
: html`
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user