diff --git a/src/controller/subtitle-stream-controller.js b/src/controller/subtitle-stream-controller.js index 5e2d71286ab..b2770125e68 100644 --- a/src/controller/subtitle-stream-controller.js +++ b/src/controller/subtitle-stream-controller.js @@ -146,7 +146,15 @@ class SubtitleStreamController extends TaskLoop { onSubtitleTrackSwitch (data) { this.currentTrackId = data.id; - this.clearVttFragQueues(); + if (this.currentTrackId === -1) + return; + + // Check if track was already loaded and if so make sure we finish + // downloading its frags, if not all have been downloaded yet + const currentTrack = this.tracks[this.currentTrackId]; + let details = currentTrack.details; + if (details !== undefined) + this.tick(); } // Got a new set of subtitle fragments. diff --git a/src/controller/timeline-controller.js b/src/controller/timeline-controller.js index 497fc8ec1af..0a9a9ddb1bb 100644 --- a/src/controller/timeline-controller.js +++ b/src/controller/timeline-controller.js @@ -255,6 +255,13 @@ class TimelineController extends EventHandler { // Parse the WebVTT file contents. WebVTTParser.parse(payload, this.initPTS, vttCCs, frag.cc, function (cues) { const currentTrack = textTracks[frag.trackId]; + // WebVTTParser.parse is an async method and if the currently selected text track mode is set to "disabled" + // before parsing is done then don't try to access currentTrack.cues.getCueById as cues will be null + // and trying to access getCueById method of cues will throw an exception + if (currentTrack.mode === 'disabled') { + hls.trigger(Event.SUBTITLE_FRAG_PROCESSED, { success: false, frag: frag }); + return; + } // Add cues and trigger event with success true. cues.forEach(cue => { // Sometimes there are cue overlaps on segmented vtts so the same @@ -269,7 +276,8 @@ class TimelineController extends EventHandler { currentTrack.addCue(textTrackCue); } } - }); + } + ); hls.trigger(Event.SUBTITLE_FRAG_PROCESSED, { success: true, frag: frag }); }, function (e) { diff --git a/tests/functional/auto/setup.js b/tests/functional/auto/setup.js index 638a2b0b910..e60865d79d6 100644 --- a/tests/functional/auto/setup.js +++ b/tests/functional/auto/setup.js @@ -160,7 +160,7 @@ describe('testing hls.js playback in the browser on "' + browserDescription + '" window.switchToHighestLevel('next'); }; window.setTimeout(function () { - var readyState = video.readyState; + let readyState = video.readyState; console.log('[log] > readyState:' + readyState); callback({ code: readyState, logs: window.logString }); }, 12000);