Skip to content

Commit 059563e

Browse files
committed
update timeline marker initialization flow to work with v4 initialization
1 parent 4705b37 commit 059563e

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/ts/utils/TimelineMarkersHandler.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,36 @@ export class TimelineMarkersHandler {
8181

8282
this.player.on(this.player.exports.PlayerEvent.AdBreakStarted, () => this.clearMarkers());
8383
this.player.on(this.player.exports.PlayerEvent.AdBreakFinished, () => this.updateMarkers());
84-
// Update markers when the size of the seekbar changes
85-
this.player.on(this.player.exports.PlayerEvent.PlayerResized, () => this.updateMarkersDOM());
8684

87-
this.player.on(this.player.exports.PlayerEvent.SourceLoaded, () => {
88-
if (this.player.isLive()) {
89-
// Update marker position as timeshift range changes
90-
this.player.on(this.player.exports.PlayerEvent.TimeChanged, () => this.updateMarkers());
91-
// Update marker postion when paused as timeshift range changes
92-
this.configureLivePausedTimeshiftUpdater(() => this.updateMarkers());
85+
const liveStreamDetector = new PlayerUtils.LiveStreamDetector(this.player, this.uimanager);
86+
liveStreamDetector.onLiveChanged.subscribe((sender, args: PlayerUtils.LiveStreamDetectorEventArgs) => {
87+
if (args.live) {
88+
this.player.on(this.player.exports.PlayerEvent.TimeShift, onTimeShift);
89+
this.player.on(this.player.exports.PlayerEvent.TimeShifted, onTimeShifted);
90+
this.uimanager.onSeekPreview.subscribe(onSeekPreview);
91+
92+
this.startLiveMarkerUpdater();
9393
}
9494
});
95+
liveStreamDetector.detect(); // Initial detection
96+
9597
this.uimanager.getConfig().events.onUpdated.subscribe(() => this.updateMarkers());
9698
this.uimanager.onRelease.subscribe(() =>
9799
this.uimanager.getConfig().events.onUpdated.unsubscribe(() => this.updateMarkers()),
98100
);
99101

102+
// Refresh the playback position when the player resized or the UI is configured. The playback position marker
103+
// is positioned absolutely and must therefore be updated when the size of the seekbar changes.
104+
this.player.on(this.player.exports.PlayerEvent.PlayerResized, () => this.updateMarkersDOM());
105+
// Additionally, when this code is called, the seekbar is not part of the UI yet and therefore does not have a size,
106+
// resulting in a wrong initial position of the marker. Refreshing it once the UI is configured solved this issue.
107+
this.uimanager.onConfigured.subscribe(() => {
108+
this.updateMarkers();
109+
});
110+
this.player.on(this.player.exports.PlayerEvent.SourceLoaded, () => {
111+
this.updateMarkers();
112+
});
113+
100114
// Init markers at startup
101115
this.updateMarkers();
102116
}
@@ -152,6 +166,13 @@ export class TimelineMarkersHandler {
152166
}
153167

154168
private updateMarkers(): void {
169+
const seekBarWidth = this.getSeekBarWidth();
170+
if (seekBarWidth === 0) {
171+
// Skip marker update when the seekBarWidth is not yet available.
172+
// Will be updated by PlayerResized/onConfigured events once dimensions are available.
173+
return;
174+
}
175+
155176
if (!shouldProcessMarkers(this.player, this.uimanager)) {
156177
this.clearMarkers();
157178
return;

0 commit comments

Comments
 (0)