mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +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"
|
||||
| "on"
|
||||
| "unavailable"
|
||||
| "unknown";
|
||||
| "unknown"
|
||||
| "standby"
|
||||
| "buffering";
|
||||
}
|
||||
|
||||
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 {
|
||||
const now = new Date().toISOString();
|
||||
return {
|
||||
@ -88,9 +84,13 @@ export class BrowserMediaPlayer {
|
||||
|
||||
toStateObj(): MediaPlayerEntity {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
|
||||
const base = BrowserMediaPlayer.idleStateObj();
|
||||
base.state = this.isPlaying ? "playing" : "paused";
|
||||
base.attributes = {
|
||||
const stateObj = BrowserMediaPlayer.idleStateObj();
|
||||
stateObj.state = this.buffering
|
||||
? "buffering"
|
||||
: this.player.paused || this.player.ended
|
||||
? "paused"
|
||||
: "playing";
|
||||
stateObj.attributes = {
|
||||
media_title: this.item.title,
|
||||
entity_picture: this.item.thumbnail,
|
||||
volume_level: this.player.volume,
|
||||
@ -103,10 +103,10 @@ export class BrowserMediaPlayer {
|
||||
};
|
||||
|
||||
if (this.player.duration) {
|
||||
base.attributes.media_duration = this.player.duration;
|
||||
base.attributes.media_position = this.player.currentTime;
|
||||
base.attributes.media_position_updated_at = base.last_updated;
|
||||
stateObj.attributes.media_duration = this.player.duration;
|
||||
stateObj.attributes.media_position = this.player.currentTime;
|
||||
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 class="controls-progress">
|
||||
${this._browserPlayer?.buffering
|
||||
${stateObj.state === "buffering"
|
||||
? html` <ha-circular-progress active></ha-circular-progress> `
|
||||
: html`
|
||||
<div class="controls">
|
||||
|
Loading…
x
Reference in New Issue
Block a user