From b2336aacc9412a1ce0d3bb0ced71ec3ee3421033 Mon Sep 17 00:00:00 2001 From: Alex Barstow Date: Tue, 23 Mar 2021 14:56:17 -0400 Subject: [PATCH] fix: remove extra timeupdate event when progress controls is disabled (#7142) --- .../progress-control/progress-control.js | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/js/control-bar/progress-control/progress-control.js b/src/js/control-bar/progress-control/progress-control.js index 3d1530768..c1943e363 100644 --- a/src/js/control-bar/progress-control/progress-control.js +++ b/src/js/control-bar/progress-control/progress-control.js @@ -5,6 +5,7 @@ import Component from '../../component.js'; import * as Dom from '../../utils/dom.js'; import clamp from '../../utils/clamp.js'; import {bind, throttle, UPDATE_REFRESH_INTERVAL} from '../../utils/fn.js'; +import {silencePromise} from '../../utils/promise'; import './seek-bar.js'; @@ -137,11 +138,23 @@ class ProgressControl extends Component { this.off(['mousedown', 'touchstart'], this.handleMouseDown); this.off(this.el_, 'mousemove', this.handleMouseMove); - this.handleMouseUp(); + + this.removeListenersAddedOnMousedownAndTouchstart(); this.addClass('disabled'); this.enabled_ = false; + + // Restore normal playback state if controls are disabled while scrubbing + if (this.player_.scrubbing()) { + const seekBar = this.getChild('seekBar'); + + this.player_.scrubbing(false); + + if (seekBar.videoWasPlaying) { + silencePromise(this.player_.play()); + } + } } /** @@ -161,6 +174,18 @@ class ProgressControl extends Component { this.enabled_ = true; } + /** + * Cleanup listeners after the user finishes interacting with the progress controls + */ + removeListenersAddedOnMousedownAndTouchstart() { + const doc = this.el_.ownerDocument; + + this.off(doc, 'mousemove', this.throttledHandleMouseSeek); + this.off(doc, 'touchmove', this.throttledHandleMouseSeek); + this.off(doc, 'mouseup', this.handleMouseUp); + this.off(doc, 'touchend', this.handleMouseUp); + } + /** * Handle `mousedown` or `touchstart` events on the `ProgressControl`. * @@ -194,17 +219,13 @@ class ProgressControl extends Component { * @listens mouseup */ handleMouseUp(event) { - const doc = this.el_.ownerDocument; const seekBar = this.getChild('seekBar'); if (seekBar) { seekBar.handleMouseUp(event); } - this.off(doc, 'mousemove', this.throttledHandleMouseSeek); - this.off(doc, 'touchmove', this.throttledHandleMouseSeek); - this.off(doc, 'mouseup', this.handleMouseUp); - this.off(doc, 'touchend', this.handleMouseUp); + this.removeListenersAddedOnMousedownAndTouchstart(); } }