Skip to content

Commit

Permalink
Merge pull request #26 from Pluto-tv/bugfix/PLBCK-140
Browse files Browse the repository at this point in the history
[PLBCK-140] Fix for closed captions not showing when seeking into the start of the playlist.
  • Loading branch information
jfconti authored May 3, 2024
2 parents 3075358 + 0122ea6 commit a6a6751
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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

0 comments on commit a6a6751

Please sign in to comment.