// current position for a program
getPercent(start, stop, delay) {
const startTime = start.getTime()
const stopTime = stop.getTime()
const elapsed = Date.now() - startTime - delay * 1000;
const length = stopTime - startTime;
if (elapsed < 0 || length < 0) return '0';
if (elapsed > length) return '100%';
return `${Math.floor((elapsed / length) * 100)}%`;
}
// progress
getElapsed (start, stop, delay) {
let time = 0;
const startTime = start.getTime()
const stopTime = stop.getTime()
const elapsed = Date.now() - startTime - delay * 1000
const length = stopTime - startTime;
if (elapsed && length && elapsed < length) time = elapsed;
return time;
}
// duration
getDuration(start, stop) {
return stop.getTime() - start.getTime();
}
// refresh interval (1s)
refreshProgramme() {
const programme = this.currentProgramme;
const start = programme.start;
const stop = programme.stop;
this.updateHtml(`${start} - ${stop}`);
if (delay) {
const elapsed = getElapsed();
const duration = getDuration();
this.updateHtml(`${elapsed} / ${duration}`);
}
this.updateSeek();
}
// update seek
updateSeek() {
if (this.isChannelPaused()) return;
const progress = this.getPercent();
const duration = this.getElapsed();
const time = DateHelper.format(duration, DateHelper.HH_MM_SS);
this.updateSeekHtml(progress, time);
}