1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-02 09:11:54 +02:00

fix: remove extra timeupdate event when progress controls is disabled (#7142)

This commit is contained in:
Alex Barstow 2021-03-23 14:56:17 -04:00 committed by GitHub
parent 0cc8684120
commit b2336aacc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
}