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"
| "on"
| "unavailable"
| "unknown";
| "unknown"
| "standby"
| "buffering";
}
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 {
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;
}
}

View File

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