Skip to content

Commit

Permalink
fix: chapters disappearing after preload none (#998)
Browse files Browse the repository at this point in the history
fixes a bug when starting playback after preload none the chapters
disappear

---------

Co-authored-by: Christian Pillsbury <cjpillsbury@gmail.com>
  • Loading branch information
luwes and cjpillsbury authored Oct 3, 2024
1 parent 1088443 commit 0f9d0fb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/playback-core/src/text-tracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ export function setupTextTracks(
});
});

const forceHiddenThumbnails = () => {
const forceHiddenTracks = () => {
// Keeping this a forEach in case we want to expand the scope of this.
Array.from(mediaEl.textTracks).forEach((track) => {
if (['subtitles', 'caption'].includes(track.kind)) return;
if (track.label !== 'thumbnails') return;
if (!(track.label === 'thumbnails' || track.kind === 'chapters')) return;
if (!track.cues?.length) {
const trackEl = mediaEl.querySelector('track[label="thumbnails"]');
let selector = 'track';
if (track.kind) selector += `[kind="${track.kind}"]`;
if (track.label) selector += `[label="${track.label}"]`;
const trackEl = mediaEl.querySelector(selector);
// Force a reload of the cues if they've been removed
const src = trackEl?.getAttribute('src') ?? '';
trackEl?.removeAttribute('src');
Expand All @@ -127,8 +130,8 @@ export function setupTextTracks(

// hls.js will forcibly clear all cues from tracks on manifest loads or media attaches.
// This ensures that we re-load them after it's done that.
hls.once(Hls.Events.MANIFEST_LOADED, forceHiddenThumbnails);
hls.once(Hls.Events.MEDIA_ATTACHED, forceHiddenThumbnails);
hls.once(Hls.Events.MANIFEST_LOADED, forceHiddenTracks);
hls.once(Hls.Events.MEDIA_ATTACHED, forceHiddenTracks);
}

export function addTextTrack(
Expand Down

0 comments on commit 0f9d0fb

Please sign in to comment.