Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLBCK-140] Fix for closed captions not showing when seeking into the start of the playlist. #26

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2959,6 +2959,8 @@ export class SubtitleStreamController extends BaseStreamController implements Ne
onManifestLoading(): void;
// (undocumented)
onMediaDetaching(): void;
// (undocumented)
onMediaSeeking(): void;
// Warning: (ae-forgotten-export) The symbol "SubtitleFragProcessed" needs to be exported by the entry point hls.d.ts
//
// (undocumented)
Expand Down
34 changes: 34 additions & 0 deletions src/controller/subtitle-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,40 @@ export class SubtitleStreamController
}
}

onMediaSeeking() {
// Find the currently showing subtitle track
const tracks = this.media?.textTracks || [];
let track;
for (let i = 0; i < tracks.length; i++) {
const textTrack = tracks[i];
if (
textTrack.mode != 'disabled' &&
(textTrack.kind == 'subtitles' || textTrack.kind == 'captions')
) {
track = textTrack;
break;
}
}

// Manually reset the cues and fragments
if (track?.cues && this.media) {
// Clear all text track cues
Array.from(track.cues).forEach((cue) => track.removeCue(cue));

// Clear all loaded subtitle fragments
this.fragmentTracker.removeFragmentsInRange(
0,
this.media.duration,
PlaylistLevelType.SUBTITLE
);

// Clear internal buffered lists
this.tracksBuffered.forEach((_, index, tracks) => (tracks[index] = []));
}

this.fragPrevious = null;
}

// If something goes wrong, proceed to next frag, if we were processing one.
onError(event: Events.ERROR, data: ErrorData) {
const frag = data.frag;
Expand Down
Loading