Skip to content

Commit 2ac6a66

Browse files
joeyparrishAnteWall
authored andcommitted
Stop constant spurious time updates in UI
Instead of updating the time display in the UI constantly, only update it if the text changes. This makes it much easier to debug the style of the UI while the video is paused, since a paused video has no reason to update the UI. Change-Id: I501e3e39efaf1ae423695aae397dbe1ce08a015b
1 parent d4c5fdf commit 2ac6a66

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

ui/presentation_time.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ shaka.ui.PresentationTimeTracker = class extends shaka.ui.Element {
3737

3838
this.currentTime_ = shaka.util.Dom.createHTMLElement('button');
3939
this.currentTime_.classList.add('shaka-current-time');
40-
this.currentTime_.textContent = '0:00';
40+
this.setValue_('0:00');
4141
this.parent.appendChild(this.currentTime_);
4242

4343
this.eventManager.listen(this.currentTime_, 'click', () => {
@@ -56,10 +56,18 @@ shaka.ui.PresentationTimeTracker = class extends shaka.ui.Element {
5656
});
5757
}
5858

59+
/** @private */
60+
setValue_(value) {
61+
// To avoid constant updates to the DOM, which makes debugging more
62+
// difficult, only set the value if it has changed. If we don't do this
63+
// check, the DOM updates constantly, this element flashes in the debugger
64+
// in Chrome, and you can't make changes in the CSS panel.
65+
if (value != this.currentTime_.textContent) {
66+
this.currentTime_.textContent = value;
67+
}
68+
}
5969

60-
/**
61-
* @private
62-
*/
70+
/** @private */
6371
updateTime_() {
6472
const isSeeking = this.controls.isSeeking();
6573
let displayTime = this.controls.getDisplayTime();
@@ -80,24 +88,21 @@ shaka.ui.PresentationTimeTracker = class extends shaka.ui.Element {
8088
// The button should only be clickable when it's live stream content, and
8189
// the current play time is behind live edge.
8290
if ((displayTime >= 1) || isSeeking) {
83-
this.currentTime_.textContent =
84-
'- ' + this.buildTimeString_(displayTime, showHour);
91+
this.setValue_('- ' + this.buildTimeString_(displayTime, showHour));
8592
this.currentTime_.disabled = false;
8693
} else {
87-
this.currentTime_.textContent =
88-
this.localization.resolve(shaka.ui.Locales.Ids.LIVE);
94+
this.setValue_(this.localization.resolve(shaka.ui.Locales.Ids.LIVE));
8995
this.currentTime_.disabled = true;
9096
}
9197
} else {
9298
const showHour = duration >= 3600;
9399

94-
this.currentTime_.textContent =
95-
this.buildTimeString_(displayTime, showHour);
96-
100+
let value = this.buildTimeString_(displayTime, showHour);
97101
if (duration) {
98-
this.currentTime_.textContent += ' / ' +
102+
value += ' / ' +
99103
this.buildTimeString_(duration, showHour);
100104
}
105+
this.setValue_(value);
101106
this.currentTime_.disabled = true;
102107
}
103108
}

0 commit comments

Comments
 (0)