Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
fix duplicate caption processing
Browse files Browse the repository at this point in the history
  • Loading branch information
squarebracket committed Aug 18, 2017
1 parent 9e6a1d9 commit aee6ee2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/flash-source-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,18 @@ export default class FlashSourceBuffer extends videojs.EventTarget {
removeCuesFromTrack(0, Infinity, this.inbandTextTrack_);
});

this.mediaSource_.player_.tech_.on('hls-reset-everything', this.resetEverything);

this.mediaSource_.player_.tech_.hls.on('dispose', () => {
this.transmuxer_.terminate();
this.mediaSource_.player_.tech_.off('hls-reset-everything', this.resetEverything);
});
}

resetEverything() {
this.transmuxer_.postMessage({action: 'resetCaptions'});
}

/**
* Append bytes to the sourcebuffers buffer, in this case we
* have to append it to swf object.
Expand Down
5 changes: 5 additions & 0 deletions src/flash-transmuxer-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class MessageHandlers {
flush() {
this.transmuxer.flush();
}

resetCaptions() {
this.transmuxer.resetCaptions();
}

}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/html-media-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ export default class HtmlMediaSource extends videojs.EventTarget {
});
};

this.onPlayerResetEverything_ = () => {
this.sourceBuffers.forEach((sourceBuffer) => {
if (sourceBuffer.transmuxer_) {
sourceBuffer.transmuxer_.postMessage({action: 'resetCaptions'});
}
});
};

// Re-emit MediaSource events on the polyfill
[
'sourceopen',
Expand All @@ -180,6 +188,8 @@ export default class HtmlMediaSource extends videojs.EventTarget {

this.player_ = videojs(video.parentNode);

this.player_.tech_.on('hls-reset-everything', this.onPlayerResetEverything_);

if (this.player_.audioTracks && this.player_.audioTracks()) {
this.player_.audioTracks().on('change', this.updateActiveSourceBuffers_);
this.player_.audioTracks().on('addtrack', this.updateActiveSourceBuffers_);
Expand Down Expand Up @@ -230,6 +240,7 @@ export default class HtmlMediaSource extends videojs.EventTarget {
// event handlers left to unbind anyway
if (this.player_.el_) {
this.player_.off('mediachange', this.onPlayerMediachange_);
this.player_.tech_.off('hls-reset-everything', this.onPlayerResetEverything_);
}
});
}
Expand Down
5 changes: 5 additions & 0 deletions src/transmuxer-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ class MessageHandlers {
flush(data) {
this.transmuxer.flush();
}

resetCaptions() {
this.transmuxer.resetCaptions();
}

}

/**
Expand Down

0 comments on commit aee6ee2

Please sign in to comment.