Skip to content

Commit 0d6cdd9

Browse files
committed
refactor: optimize initialization of video player components by using Promise.all for concurrent loading
1 parent 452eb98 commit 0d6cdd9

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

packages/video-player/javascript/index.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,33 @@ class ImageKitVideoPlayerPlugin extends Plugin {
7474
this.shoppableManager_ = undefined;
7575
}
7676

77+
const initPromises: Promise<void>[] = [];
78+
7779
if (this.ikGlobalSettings_.seekThumbnails && this.currentSource_) {
78-
const mgr = await SeekThumbnailsManager.initSeekThumbnails(
79-
this.player,
80-
this.currentSource_,
81-
this.ikGlobalSettings_
80+
initPromises.push(
81+
SeekThumbnailsManager.initSeekThumbnails(
82+
this.player,
83+
this.currentSource_,
84+
this.ikGlobalSettings_
85+
).then(mgr => {
86+
if (mgr) {
87+
this.seekThumbnailsManager_ = mgr;
88+
}
89+
})
8290
);
83-
if (mgr) {
84-
this.seekThumbnailsManager_ = mgr;
85-
}
8691
}
8792

88-
await initChapterMarkers(this.player, this.currentSource_, this.ikGlobalSettings_, this.ikGlobalSettings_.signerFn);
89-
await this.initRecommendationsOverlay();
93+
initPromises.push(
94+
initChapterMarkers(this.player, this.currentSource_, this.ikGlobalSettings_, this.ikGlobalSettings_.signerFn)
95+
);
9096

91-
if (this.currentSource_ && this.currentSource_.shoppable) {
97+
initPromises.push(this.initRecommendationsOverlay());
98+
99+
if (this.currentSource_?.shoppable) {
92100
this.shoppableManager_ = new ShoppableManager(this.player, this.currentSource_);
93101
}
102+
103+
await Promise.all(initPromises);
94104
});
95105

96106
this.player.ready(() => {

packages/video-player/javascript/modules/chapters/chapters.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ export async function initChapterMarkers(
8686
ikGlobalSettings: IKPlayerOptions,
8787
signerFn?: (src: string) => Promise<string>
8888
): Promise<void> {
89+
90+
cleanupChapterTextTracks(player);
91+
cleanupChapterLabelDisplay(player);
92+
const existing = player.getChild('ChapterMarkersProgressBarControl');
93+
if (existing) {
94+
existing.dispose();
95+
}
96+
8997
if (!source) return;
9098

9199
const src = Array.isArray(source) ? source[0] : source;
@@ -152,7 +160,6 @@ export async function initChapterMarkers(
152160
}
153161

154162
if (chapterList.length) {
155-
cleanupChapterTextTracks(player);
156163

157164
try {
158165
const trackEl = player.addRemoteTextTrack(
@@ -168,7 +175,6 @@ export async function initChapterMarkers(
168175
trackEl.track.addCue(cue);
169176
});
170177

171-
cleanupChapterLabelDisplay(player);
172178
setupChapterLabelDisplay(player, trackEl.track);
173179

174180
const controlBar = player.getChild('ControlBar');

0 commit comments

Comments
 (0)