Skip to content

Commit 750eb92

Browse files
committed
update with restart captions on load
1 parent b8dc334 commit 750eb92

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

packages/youtube-video-element/youtube-video-element.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ class YoutubeVideoElement extends (globalThis.HTMLElement ?? class {}) {
224224
playFired = true;
225225
this.dispatchEvent(new Event('play'));
226226
}
227+
const captionList = this.api.getOption('captions', 'tracklist') || [];
228+
229+
captionList.forEach((t) => {
230+
if (![...this.textTracks].some((tt) => tt.language === t.languageCode)) {
231+
this.#textTracksVideo.addTextTrack('subtitles', t.displayName, t.languageCode);
232+
}
233+
this.textTracks = this.#textTracksVideo.textTracks;
234+
});
235+
236+
this.dispatchEvent(new Event('loadstart'));
227237
}
228238

229239
if (state === YT.PlayerState.PLAYING) {
@@ -252,16 +262,6 @@ class YoutubeVideoElement extends (globalThis.HTMLElement ?? class {}) {
252262
this.play();
253263
}
254264
}
255-
if (state === YT.PlayerState.CUED || state === YT.PlayerState.PLAYING) {
256-
const captionList = this.api.getOption('captions', 'tracklist') || [];
257-
258-
captionList.forEach((t) => {
259-
if (![...this.textTracks].some((tt) => tt.language === t.languageCode)) {
260-
this.#textTracksVideo.addTextTrack('subtitles', t.displayName, t.languageCode);
261-
}
262-
this.textTracks = this.#textTracksVideo.textTracks;
263-
});
264-
}
265265
});
266266

267267
this.api.addEventListener('onPlaybackRateChange', () => {

0 commit comments

Comments
 (0)