Skip to content

Commit e2aa1ab

Browse files
committed
fix(UI): Align seek bar chapter markers with the playhead thumb
1 parent ce7ee4b commit e2aa1ab

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

ui/seek_bar.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ shaka.ui.SeekBar = class extends shaka.ui.RangeElement {
532532
const minSeekBarWindow =
533533
shaka.ui.SeekBar.MIN_SEEK_WINDOW_TO_SHOW_SEEKBAR_;
534534
if (seekRangeSize < minSeekBarWindow) {
535+
if (seekRangeSize <= 0) {
536+
this.chaptersTimer_.tickAfter(/* seconds= */ 0.1);
537+
return;
538+
}
535539
this.chapterMarkerContainer_.style.background = 'transparent';
536540
this.chaptersTimer_?.stop();
537541
return;
@@ -560,9 +564,23 @@ shaka.ui.SeekBar = class extends shaka.ui.RangeElement {
560564
return;
561565
}
562566

567+
const rect = this.bar.getBoundingClientRect();
568+
const thumbSize = 12;
569+
const barMin = parseFloat(this.bar.min);
570+
const barMax = parseFloat(this.bar.max);
571+
const barRange = barMax - barMin;
572+
573+
if (rect.width === 0 || barRange === 0) {
574+
this.chaptersTimer_.tickAfter(/* seconds= */ 0.1);
575+
return;
576+
}
577+
563578
const sortedPoints = Array.from(points).sort((a, b) => a - b);
564579
for (const point of sortedPoints) {
565-
const start = ((point - seekRange.start) / seekRangeSize) * 100 + '%';
580+
const fraction = (point - barMin) / barRange;
581+
const pixelPos = fraction * (rect.width - thumbSize) + thumbSize / 2;
582+
const startPct = (pixelPos / rect.width) * 100;
583+
const start = startPct + '%';
566584
const end = `calc(${start} + 2px)`;
567585

568586
gradient.push(`transparent ${start}`);
@@ -840,7 +858,7 @@ shaka.ui.SeekBar = class extends shaka.ui.RangeElement {
840858
getChapter_(totalSeconds) {
841859
for (const chapter of this.controls.getChapters()) {
842860
if (chapter.startTime <= totalSeconds &&
843-
chapter.endTime >= totalSeconds) {
861+
chapter.endTime > totalSeconds) {
844862
return chapter;
845863
}
846864
}

0 commit comments

Comments
 (0)