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 (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
squarebracket authored and mjneil committed Aug 18, 2017
1 parent 8acf6e8 commit fa15919
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/flash-source-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,13 @@ export default class FlashSourceBuffer extends videojs.EventTarget {
}
});

let onHlsReset = this.onHlsReset_.bind(this);

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

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

Expand Down Expand Up @@ -547,4 +552,8 @@ export default class FlashSourceBuffer extends videojs.EventTarget {

return tags;
}

onHlsReset_() {
this.transmuxer_.postMessage({action: 'resetCaptions'});
}
}
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.onHlsReset_ = () => {
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', this.onHlsReset_);

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', this.onHlsReset_);
}
});
}
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 fa15919

Please sign in to comment.