Skip to content

Commit 8b9fa4b

Browse files
committed
fix(player): update chapter index correctly on live streams
1 parent 873a360 commit 8b9fa4b

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

packages/vidstack/src/components/ui/sliders/time-slider/slider-chapters.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,25 @@ export class SliderChapters extends Component<SliderChaptersProps> {
151151
const { liveEdge, ended } = this._media.$state;
152152

153153
let { fillPercent, value } = this._sliderState,
154+
isLiveEdge = liveEdge(),
154155
prevActiveIndex = peek(this._activeIndex),
155156
currentChapter = this._cues[prevActiveIndex],
156-
currentActiveIndex = this._findActiveChapterIndex(
157-
currentChapter.startTime <= peek(value) ? prevActiveIndex : 0,
158-
fillPercent(),
159-
);
160-
161-
if (liveEdge() || ended()) {
157+
currentActiveIndex = isLiveEdge
158+
? this._cues.length - 1
159+
: this._findActiveChapterIndex(
160+
currentChapter.startTime <= peek(value) ? prevActiveIndex : 0,
161+
fillPercent(),
162+
);
163+
164+
if (isLiveEdge || ended()) {
162165
this._updateFillPercents(0, this._cues.length, '100%');
163166
} else if (currentActiveIndex > prevActiveIndex) {
164167
this._updateFillPercents(prevActiveIndex, currentActiveIndex, '100%');
165168
} else if (currentActiveIndex < prevActiveIndex) {
166169
this._updateFillPercents(currentActiveIndex + 1, prevActiveIndex + 1, '0%');
167170
}
168171

169-
const percent = liveEdge()
172+
const percent = isLiveEdge
170173
? '100%'
171174
: this._calcPercent(this._cues[currentActiveIndex], fillPercent()) + '%';
172175

0 commit comments

Comments
 (0)