Use fast time to decimal for non display calculations

This commit is contained in:
Ajay 2022-12-11 14:10:09 -05:00
parent 41a25720d0
commit cf0e91c4ff

View file

@ -531,7 +531,7 @@ class PreviewBar {
const nextSegment = segments[index + 1];
const nextTime = nextSegment ? nextSegment.segment[0] : this.videoDuration;
const lastTime = result[result.length - 1]?.segment[1] || segment.segment[1];
if (this.intervalToDecimal(lastTime, nextTime) > MIN_CHAPTER_SIZE) {
if (this.fastIntervalToDecimal(lastTime, nextTime) > MIN_CHAPTER_SIZE) {
result.push({
segment: [lastTime, nextTime],
originalDuration: 0,
@ -866,7 +866,7 @@ class PreviewBar {
}
private chapterGroupFilter(segment: SegmentContainer): boolean {
return segment.segment.length === 2 && this.intervalToDecimal(segment.segment[0], segment.segment[1]) > MIN_CHAPTER_SIZE;
return segment.segment.length === 2 && this.fastIntervalToDecimal(segment.segment[0], segment.segment[1]) > MIN_CHAPTER_SIZE;
}
intervalToPercentage(startTime: number, endTime: number) {
@ -877,6 +877,10 @@ class PreviewBar {
return (this.timeToDecimal(endTime) - this.timeToDecimal(startTime));
}
fastIntervalToDecimal(startTime: number, endTime: number) {
return (this.fastTimeToDecimal(endTime) - this.fastTimeToDecimal(startTime));
}
timeToPercentage(time: number): string {
return `${this.timeToDecimal(time) * 100}%`
}
@ -912,6 +916,10 @@ class PreviewBar {
}
}
return this.fastTimeToDecimal(time);
}
fastTimeToDecimal(time: number): number {
return Math.min(1, time / this.videoDuration);
}