mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 12:56:37 +00:00
Update media player progress bar (#458)
* Show progress during paused state * Hide progress if there's no media_duration * Only periodically update when playing and showing progress
This commit is contained in:
parent
2222944137
commit
de64c766f6
@ -279,15 +279,16 @@ Polymer({
|
|||||||
this.$.cover.style.backgroundImage = '';
|
this.$.cover.style.backgroundImage = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerObj.isPlaying) {
|
if (playerObj.isPlaying && playerObj.showProgress) {
|
||||||
if (!this._positionTracking) {
|
if (!this._positionTracking) {
|
||||||
this._positionTracking = setInterval(this.updatePlaybackPosition, 1000);
|
this._positionTracking = setInterval(this.updatePlaybackPosition, 1000);
|
||||||
}
|
}
|
||||||
this.updatePlaybackPosition();
|
|
||||||
} else if (this._positionTracking) {
|
} else if (this._positionTracking) {
|
||||||
clearInterval(this._positionTracking);
|
clearInterval(this._positionTracking);
|
||||||
this._positionTracking = null;
|
this._positionTracking = null;
|
||||||
this.playbackPosition = 0;
|
}
|
||||||
|
if (playerObj.showProgress) {
|
||||||
|
this.updatePlaybackPosition();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -51,15 +51,18 @@
|
|||||||
addGetter('showProgress', function () {
|
addGetter('showProgress', function () {
|
||||||
return (
|
return (
|
||||||
(this.isPlaying || this.isPaused) &&
|
(this.isPlaying || this.isPaused) &&
|
||||||
|
'media_duration' in this.stateObj.attributes &&
|
||||||
'media_position' in this.stateObj.attributes &&
|
'media_position' in this.stateObj.attributes &&
|
||||||
'media_position_updated_at' in this.stateObj.attributes);
|
'media_position_updated_at' in this.stateObj.attributes);
|
||||||
});
|
});
|
||||||
|
|
||||||
addGetter('currentProgress', function () {
|
addGetter('currentProgress', function () {
|
||||||
return (
|
var progress = this.stateObj.attributes.media_position;
|
||||||
this.stateObj.attributes.media_position +
|
if (this.isPlaying) {
|
||||||
((Date.now() -
|
progress += (Date.now() -
|
||||||
new Date(this.stateObj.attributes.media_position_updated_at)) / 1000));
|
new Date(this.stateObj.attributes.media_position_updated_at).getTime()) / 1000.0;
|
||||||
|
}
|
||||||
|
return progress;
|
||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable no-bitwise */
|
/* eslint-disable no-bitwise */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user