mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-13 20:36:35 +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 = '';
|
||||
}
|
||||
|
||||
if (playerObj.isPlaying) {
|
||||
if (playerObj.isPlaying && playerObj.showProgress) {
|
||||
if (!this._positionTracking) {
|
||||
this._positionTracking = setInterval(this.updatePlaybackPosition, 1000);
|
||||
}
|
||||
this.updatePlaybackPosition();
|
||||
} else if (this._positionTracking) {
|
||||
clearInterval(this._positionTracking);
|
||||
this._positionTracking = null;
|
||||
this.playbackPosition = 0;
|
||||
}
|
||||
if (playerObj.showProgress) {
|
||||
this.updatePlaybackPosition();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -51,15 +51,18 @@
|
||||
addGetter('showProgress', function () {
|
||||
return (
|
||||
(this.isPlaying || this.isPaused) &&
|
||||
'media_duration' in this.stateObj.attributes &&
|
||||
'media_position' in this.stateObj.attributes &&
|
||||
'media_position_updated_at' in this.stateObj.attributes);
|
||||
});
|
||||
|
||||
addGetter('currentProgress', function () {
|
||||
return (
|
||||
this.stateObj.attributes.media_position +
|
||||
((Date.now() -
|
||||
new Date(this.stateObj.attributes.media_position_updated_at)) / 1000));
|
||||
var progress = this.stateObj.attributes.media_position;
|
||||
if (this.isPlaying) {
|
||||
progress += (Date.now() -
|
||||
new Date(this.stateObj.attributes.media_position_updated_at).getTime()) / 1000.0;
|
||||
}
|
||||
return progress;
|
||||
});
|
||||
|
||||
/* eslint-disable no-bitwise */
|
||||
|
Loading…
x
Reference in New Issue
Block a user