From dd2deda6d23c6173c4022f08c75ea56d4e46c24a Mon Sep 17 00:00:00 2001 From: Juan Conti Date: Tue, 23 Apr 2024 16:19:51 -0300 Subject: [PATCH 1/4] Merge pull request #5 from cbsinteractive/issue/246-pluto-xbox-captions issue/246-pluto-xbox-captions --- src/controller/subtitle-stream-controller.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/controller/subtitle-stream-controller.ts b/src/controller/subtitle-stream-controller.ts index 09ae988ba79..1a580ad98e1 100644 --- a/src/controller/subtitle-stream-controller.ts +++ b/src/controller/subtitle-stream-controller.ts @@ -199,6 +199,26 @@ export class SubtitleStreamController } } + onMediaSeeking() { + // Find the currently showing subtitle track + const tracks = Array.from(this.media.textTracks); + const track = tracks.find(track => track.mode != 'disabled' && (track.kind == 'subtitles' || track.kind == 'captions')); + + // Manually reset the cues and fragments + if (track && track.cues) { + // 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; From 1f9c155c9761e323efe56ecb505e9b69e994c9ae Mon Sep 17 00:00:00 2001 From: Juan Conti Date: Tue, 23 Apr 2024 17:01:44 -0300 Subject: [PATCH 2/4] PLBCK-140: Lint compliance code changes. Dealt with nullable BaseStreamController's media property. --- src/controller/subtitle-stream-controller.ts | 29 ++++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/controller/subtitle-stream-controller.ts b/src/controller/subtitle-stream-controller.ts index 1a580ad98e1..77b85d2f020 100644 --- a/src/controller/subtitle-stream-controller.ts +++ b/src/controller/subtitle-stream-controller.ts @@ -200,20 +200,37 @@ export class SubtitleStreamController } onMediaSeeking() { + if (!this.media) { + return; + } // Find the currently showing subtitle track - const tracks = Array.from(this.media.textTracks); - const track = tracks.find(track => track.mode != 'disabled' && (track.kind == 'subtitles' || track.kind == 'captions')); + 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 && track.cues) { + if (track?.cues) { // Clear all text track cues - Array.from(track.cues).forEach(cue => track.removeCue(cue)); + Array.from(track.cues).forEach((cue) => track.removeCue(cue)); // Clear all loaded subtitle fragments - this.fragmentTracker.removeFragmentsInRange(0, this.media.duration, PlaylistLevelType.SUBTITLE); + this.fragmentTracker.removeFragmentsInRange( + 0, + this.media.duration, + PlaylistLevelType.SUBTITLE + ); // Clear internal buffered lists - this.tracksBuffered.forEach((_, index, tracks) => tracks[index] = []); + this.tracksBuffered.forEach((_, index, tracks) => (tracks[index] = [])); } this.fragPrevious = null; From 606815b76fc294e91ef8253f14c5003e6af21493 Mon Sep 17 00:00:00 2001 From: Juan Conti Date: Fri, 26 Apr 2024 18:14:46 -0300 Subject: [PATCH 3/4] PLBCK-140: Applied api changes from the fork. --- api-extractor/report/hls.js.api.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api-extractor/report/hls.js.api.md b/api-extractor/report/hls.js.api.md index 5380954de34..3074d9e8f7c 100644 --- a/api-extractor/report/hls.js.api.md +++ b/api-extractor/report/hls.js.api.md @@ -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) From 0122ea6338e67bf957bd9ddb6f8f03a253e41743 Mon Sep 17 00:00:00 2001 From: Juan Conti Date: Mon, 29 Apr 2024 17:15:56 -0300 Subject: [PATCH 4/4] PLBCK-140: Fixed logic for onMediaSeeking for nullable media --- src/controller/subtitle-stream-controller.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/controller/subtitle-stream-controller.ts b/src/controller/subtitle-stream-controller.ts index 77b85d2f020..02780f58dd0 100644 --- a/src/controller/subtitle-stream-controller.ts +++ b/src/controller/subtitle-stream-controller.ts @@ -200,11 +200,8 @@ export class SubtitleStreamController } onMediaSeeking() { - if (!this.media) { - return; - } // Find the currently showing subtitle track - const tracks = this.media.textTracks; + const tracks = this.media?.textTracks || []; let track; for (let i = 0; i < tracks.length; i++) { const textTrack = tracks[i]; @@ -218,7 +215,7 @@ export class SubtitleStreamController } // Manually reset the cues and fragments - if (track?.cues) { + if (track?.cues && this.media) { // Clear all text track cues Array.from(track.cues).forEach((cue) => track.removeCue(cue));