diff --git a/lib/text/ui_text_displayer.js b/lib/text/ui_text_displayer.js index 19da8918da..60b36ecbc8 100644 --- a/lib/text/ui_text_displayer.js +++ b/lib/text/ui_text_displayer.js @@ -12,6 +12,7 @@ goog.require('shaka.Deprecate'); goog.require('shaka.text.Cue'); goog.require('shaka.text.CueRegion'); goog.require('shaka.util.Dom'); +goog.require('shaka.util.EventManager'); goog.require('shaka.util.Timer'); @@ -74,6 +75,13 @@ shaka.text.UITextDisplayer = class { /** private {Map.} */ this.currentCuesMap_ = new Map(); + + /** @private {shaka.util.EventManager} */ + this.eventManager_ = new shaka.util.EventManager(); + + this.eventManager_.listen(document, 'fullscreenchange', () => { + this.updateCaptions_(/* forceUpdate= */ true); + }); } @@ -118,6 +126,12 @@ shaka.text.UITextDisplayer = class { } this.currentCuesMap_.clear(); + + // Tear-down the event manager to ensure messages stop moving around. + if (this.eventManager_) { + this.eventManager_.release(); + this.eventManager_ = null; + } } @@ -158,9 +172,10 @@ shaka.text.UITextDisplayer = class { /** * Display the current captions. + * @param {boolean=} forceUpdate * @private */ - updateCaptions_() { + updateCaptions_(forceUpdate = true) { const currentTime = this.video_.currentTime; // Return true if the cue should be displayed at the current time point. @@ -172,7 +187,7 @@ shaka.text.UITextDisplayer = class { // For each cue in the current cues map, if the cue's end time has passed, // remove the entry from the map, and remove the captions from the page. for (const cue of this.currentCuesMap_.keys()) { - if (!shouldCueBeDisplayed(cue)) { + if (!shouldCueBeDisplayed(cue) || forceUpdate) { const captions = this.currentCuesMap_.get(cue); this.textContainer_.removeChild(captions); this.currentCuesMap_.delete(cue);