replace dirty checking with timeupdate
This commit is contained in:
parent
6deeacd374
commit
e10528397f
|
|
@ -62,11 +62,11 @@ class Controller {
|
|||
percentage = Math.min(percentage, 1);
|
||||
this.player.bar.set('played', percentage, 'width');
|
||||
this.player.seek(this.player.bar.get('played', 'width') * this.player.audio.duration);
|
||||
this.player.timer.enable('progress');
|
||||
this.player.disableTimeupdate = true;
|
||||
};
|
||||
|
||||
this.player.template.barWrap.addEventListener(utils.nameMap.dragStart, () => {
|
||||
this.player.timer.disable('progress');
|
||||
this.player.disableTimeupdate = false;
|
||||
document.addEventListener(utils.nameMap.dragMove, thumbMove);
|
||||
document.addEventListener(utils.nameMap.dragEnd, thumbUp);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -121,6 +121,17 @@ class APlayer {
|
|||
}
|
||||
});
|
||||
|
||||
this.on('timeupdate', () => {
|
||||
if (!this.disableTimeupdate) {
|
||||
this.bar.set('played', this.audio.currentTime / this.audio.duration, 'width');
|
||||
this.lrc && this.lrc.update();
|
||||
const currentTime = utils.secondToTime(this.audio.currentTime);
|
||||
if (this.template.ptime.innerHTML !== currentTime) {
|
||||
this.template.ptime.innerHTML = currentTime;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// show audio time: the metadata has loaded or changed
|
||||
this.on('durationchange', () => {
|
||||
if (this.audio.duration !== 1) { // compatibility: Android browsers will output 1 at first
|
||||
|
|
@ -268,7 +279,6 @@ class APlayer {
|
|||
});
|
||||
|
||||
this.timer.enable('loading');
|
||||
this.timer.enable('progress');
|
||||
|
||||
if (this.options.mutex) {
|
||||
for (let i = 0; i < instances.length; i++) {
|
||||
|
|
@ -298,7 +308,6 @@ class APlayer {
|
|||
this.audio.pause();
|
||||
|
||||
this.timer.disable('loading');
|
||||
this.timer.disable('progress');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import utils from './utils';
|
||||
|
||||
class Timer {
|
||||
constructor (player) {
|
||||
|
|
@ -15,7 +14,7 @@ class Timer {
|
|||
}
|
||||
)();
|
||||
|
||||
this.types = ['loading', 'progress'];
|
||||
this.types = ['loading'];
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
|
@ -27,19 +26,6 @@ class Timer {
|
|||
});
|
||||
}
|
||||
|
||||
initprogressChecker () {
|
||||
this.progressChecker = setInterval(() => {
|
||||
if (this.enableprogressChecker) {
|
||||
this.player.bar.set('played', this.player.audio.currentTime / this.player.audio.duration, 'width');
|
||||
this.player.lrc && this.player.lrc.update();
|
||||
const currentTime = utils.secondToTime(this.player.audio.currentTime);
|
||||
if (this.player.template.ptime.innerHTML !== currentTime) {
|
||||
this.player.template.ptime.innerHTML = currentTime;
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
initloadingChecker () {
|
||||
let lastPlayPos = 0;
|
||||
let currentPlayPos = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue