Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed May 2, 2019
1 parent 4b3bf7f commit 04e65d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const handleInitSegmentResponse =
segment.map.bytes = new Uint8Array(request.response);

// Initialize CaptionParser if it hasn't been yet
if (!captionParser.isInitialized()) {
if (captionParser && !captionParser.isInitialized()) {
captionParser.init();
}

Expand Down Expand Up @@ -356,7 +356,7 @@ const handleSegmentBytes = ({

// Run through the CaptionParser in case there are captions.
// Initialize CaptionParser if it hasn't been yet
if (!captionParser.isInitialized()) {
if (captionParser && !captionParser.isInitialized()) {
captionParser.init();
}

Expand Down
22 changes: 17 additions & 5 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,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;

Expand Down Expand Up @@ -315,7 +319,9 @@ export default class SegmentLoader extends videojs.EventTarget {
segmentTransmuxer.dispose();
}
this.resetStats_();
this.captionParser_.reset();
if (this.captionParser_) {
this.captionParser_.reset();
}
}

setAudio(enable) {
Expand Down Expand Up @@ -679,7 +685,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();
}
}

/**
Expand Down Expand Up @@ -850,7 +858,9 @@ export default class SegmentLoader extends videojs.EventTarget {
// time 0 for the new content.
segmentInfo.timestampOffset =
buffered.length ? buffered.end(buffered.length - 1) : segmentInfo.startOfSegment;
this.captionParser_.clearAllCaptions();
if (this.captionParser_) {
this.captionParser_.clearAllCaptions();
}
}

this.loadSegment_(segmentInfo);
Expand Down Expand Up @@ -1274,7 +1284,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();
}
}

handleId3_(simpleSegment, id3Frames, dispatchType) {
Expand Down

0 comments on commit 04e65d0

Please sign in to comment.