Add support for buffering state in media browser (#15459)

This commit is contained in:
Paul Bottein 2023-02-20 14:32:13 +01:00 committed by GitHub
parent e91a477b8b
commit 1ab1cf0fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -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 {

View File

@ -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;
} }
} }

View File

@ -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">