diff --git a/src/media-segment-request.js b/src/media-segment-request.js index c61689464..10adb71b9 100644 --- a/src/media-segment-request.js +++ b/src/media-segment-request.js @@ -161,7 +161,7 @@ const handleInitSegmentResponse = (segment, captionParser, finishProcessingFn) = segment.map.bytes = new Uint8Array(request.response); // Initialize CaptionParser if it hasn't been yet - if (!captionParser.isInitialized()) { + if (captionParser && !captionParser.isInitialized()) { captionParser.init(); } @@ -210,7 +210,7 @@ const handleSegmentResponse = (segment, captionParser, finishProcessingFn) => (e // This is likely an FMP4 and has the init segment. // Run through the CaptionParser in case there are captions. - if (segment.map && segment.map.bytes) { + if (captionParser && segment.map && segment.map.bytes) { // Initialize CaptionParser if it hasn't been yet if (!captionParser.isInitialized()) { captionParser.init(); diff --git a/src/segment-loader.js b/src/segment-loader.js index 1ce865548..a0b3610a1 100644 --- a/src/segment-loader.js +++ b/src/segment-loader.js @@ -189,7 +189,11 @@ export default class SegmentLoader extends videojs.EventTarget { this.keyCache_ = {}; // Fmp4 CaptionParser - this.captionParser_ = new CaptionParser(); + if (this.loaderType_ === 'main') { + this.captionParser_ = new CaptionParser(); + } else { + this.captionParser_ = null; + } this.decrypter_ = settings.decrypter; @@ -250,7 +254,9 @@ export default class SegmentLoader extends videojs.EventTarget { this.sourceUpdater_.dispose(); } this.resetStats_(); - this.captionParser_.reset(); + if (this.captionParser_) { + this.captionParser_.reset(); + } } /** @@ -606,7 +612,9 @@ export default class SegmentLoader extends videojs.EventTarget { this.resetLoader(); this.remove(0, this.duration_(), done); // clears fmp4 captions - this.captionParser_.clearAllCaptions(); + if (this.captionParser_) { + this.captionParser_.clearAllCaptions(); + } this.trigger('reseteverything'); } @@ -739,7 +747,9 @@ export default class SegmentLoader extends videojs.EventTarget { segmentInfo.startOfSegment < this.sourceUpdater_.timestampOffset())) { this.syncController_.reset(); segmentInfo.timestampOffset = segmentInfo.startOfSegment; - this.captionParser_.clearAllCaptions(); + if (this.captionParser_) { + this.captionParser_.clearAllCaptions(); + } } this.loadSegment_(segmentInfo); @@ -1215,7 +1225,9 @@ export default class SegmentLoader extends videojs.EventTarget { }); // Reset stored captions since we added parsed // captions to a text track at this point - this.captionParser_.clearParsedCaptions(); + if (this.captionParser_) { + this.captionParser_.clearParsedCaptions(); + } } this.handleSegment_();