diff --git a/src/flash-media-source.js b/src/flash-media-source.js index ca59e61f..6642c8ad 100644 --- a/src/flash-media-source.js +++ b/src/flash-media-source.js @@ -22,14 +22,6 @@ export default class FlashMediaSource extends videojs.EventTarget { this.sourceBuffers = []; this.readyState = 'closed'; - this.onPlayerSeeked_ = () => { - this.sourceBuffers.forEach((sourceBuffer) => { - if (sourceBuffer.transmuxer_) { - sourceBuffer.transmuxer_.seeked(); - } - }); - }; - this.on(['sourceopen', 'webkitsourceopen'], (event) => { // find the swf where we will push media data this.swfObj = document.getElementById(event.swfId); @@ -37,7 +29,6 @@ export default class FlashMediaSource extends videojs.EventTarget { this.tech_ = this.swfObj.tech; this.readyState = 'open'; - this.player_.on('seeked', this.onPlayerSeeked_); this.tech_.on('seeking', () => { let i = this.sourceBuffers.length; @@ -58,12 +49,6 @@ export default class FlashMediaSource extends videojs.EventTarget { } }); - this.on('sourceclose', () => { - if (this.player_.el_) { - this.player_.off('seeked', this.onPlayerSeeked_); - } - }); - } /** diff --git a/src/flash-source-buffer.js b/src/flash-source-buffer.js index 5b7079cf..42e0cf75 100644 --- a/src/flash-source-buffer.js +++ b/src/flash-source-buffer.js @@ -178,6 +178,7 @@ export default class FlashSourceBuffer extends videojs.EventTarget { // On a seek we remove all text track data since flash has no concept // of a buffered-range and everything else is reset on seek this.mediaSource_.player_.on('seeked', () => { + this.resetCaptionsIfAppropriate(); removeCuesFromTrack(0, Infinity, this.metadataTrack_); removeCuesFromTrack(0, Infinity, this.inbandTextTrack_); }); @@ -187,6 +188,15 @@ export default class FlashSourceBuffer extends videojs.EventTarget { }); } + resetCaptionsIfAppropriate() { + let range = this.player_.buffered(); + let current = this.player_.currentTime(); + + if (range.length && current >= range.end(0) || current <= range.start(0)) { + this.transmuxer_.postMessage({action: 'resetCaptions'}); + } + } + /** * Append bytes to the sourcebuffers buffer, in this case we * have to append it to swf object. diff --git a/src/flash-transmuxer-worker.js b/src/flash-transmuxer-worker.js index 2b2cd7ac..915b698a 100644 --- a/src/flash-transmuxer-worker.js +++ b/src/flash-transmuxer-worker.js @@ -77,8 +77,8 @@ class MessageHandlers { this.transmuxer.flush(); } - seeked() { - this.transmuxer.seeked(); + resetCaptions() { + this.transmuxer.resetCaptions(); } } diff --git a/src/html-media-source.js b/src/html-media-source.js index 50a881e0..e9c3e529 100644 --- a/src/html-media-source.js +++ b/src/html-media-source.js @@ -159,10 +159,15 @@ export default class HtmlMediaSource extends videojs.EventTarget { }); }; - this.onPlayerSeeked_ = () => { + this.onPlayerSeeking_ = (event) => { this.sourceBuffers.forEach((sourceBuffer) => { if (sourceBuffer.transmuxer_) { - sourceBuffer.transmuxer_.seeked(); + let range = this.player_.buffered(); + let current = this.player_.currentTime(); + + if (current >= range.end(0) || current <= range.start(0)) { + sourceBuffer.transmuxer_.postMessage({action: 'resetCaptions'}); + } } }); }; @@ -195,7 +200,7 @@ export default class HtmlMediaSource extends videojs.EventTarget { } this.player_.on('mediachange', this.onPlayerMediachange_); - this.player_.on('seeked', this.onPlayerSeeked_); + this.player_.on('seeking', this.onPlayerSeeking_); }); this.on('sourceended', (event) => { @@ -239,7 +244,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_.off('seeked', this.onPlayerSeeked_); + this.player_.off('seeking', this.onPlayerSeeking_); } }); } diff --git a/src/transmuxer-worker.js b/src/transmuxer-worker.js index a7cef814..3881edda 100644 --- a/src/transmuxer-worker.js +++ b/src/transmuxer-worker.js @@ -133,8 +133,8 @@ class MessageHandlers { this.transmuxer.flush(); } - seeked() { - this.transmuxer.seeked(); + resetCaptions() { + this.transmuxer.resetCaptions(); } }