fix: sometimes currentTime is smaller than the totalTime when player is finished (#445)

plus: fix the problem that sometimes return value of getCurrentTime() is negative
This commit is contained in:
Lucky Feng
2020-12-18 15:32:11 +08:00
committed by GitHub
parent 5992f03c84
commit f0f32a097a
2 changed files with 3 additions and 2 deletions

View File

@@ -508,7 +508,7 @@ export class Replayer {
// defer finish event if the last event is a mouse move // defer finish event if the last event is a mouse move
setTimeout(() => { setTimeout(() => {
finish(); finish();
}, Math.max(0, -event.data.positions[0].timeOffset)); }, Math.max(0, -event.data.positions[0].timeOffset + 50)); // Add 50 to make sure the timer would check the last mousemove event. Otherwise, the timer may be stopped by the service before checking the last event.
} else { } else {
finish(); finish();
} }

View File

@@ -39,7 +39,8 @@ export class Timer {
let lastTimestamp = performance.now(); let lastTimestamp = performance.now();
const { actions } = this; const { actions } = this;
const self = this; const self = this;
function check(time: number) { function check() {
const time = performance.now();
self.timeOffset += (time - lastTimestamp) * self.speed; self.timeOffset += (time - lastTimestamp) * self.speed;
lastTimestamp = time; lastTimestamp = time;
while (actions.length) { while (actions.length) {