在拖动进度条的时候,让timeupdate的事件回调先跳过。
this.nativeAudio.addEventListener('timeupdate', () => {
if (this.isUserDraggingProgressBar) return; // 有傻逼在拖进度条,直接return
this.currentTime = this.nativeAudio.currentTime
}
this.progressBar.addEventListener('change', () => {
this.setProgressBarDragging();
this.nativeAudio.currentTime = this.progressBar.value
});
this.setProgressBarDragging = function(){
clearTimeout(this._progressBarDraggingTimer);
this._progressBarDraggingTimer = setTimeout(() => {
// debounce的效果,频繁触发setProgressBarDragging,
// 会抑制它变成false, 直到不再触发
this.isUserDraggingProgressBar = false;
}, 500);
this.isUserDraggingProgressBar = true;
};