Skip to content

Commit

Permalink
fix: Force update captions with fullscreen (shaka-project#3414)
Browse files Browse the repository at this point in the history
There are measurements that use absolute values in pixels after a conversion. By making this change, we force to update the subtitles that are being shown to have the correct dimensions.
  • Loading branch information
Álvaro Velad Galván committed May 17, 2021
1 parent a096bc1 commit b426fe8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/text/ui_text_displayer.js
Expand Up @@ -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');


Expand Down Expand Up @@ -74,6 +75,13 @@ shaka.text.UITextDisplayer = class {

/** private {Map.<!shaka.extern.Cue, !HTMLElement>} */
this.currentCuesMap_ = new Map();

/** @private {shaka.util.EventManager} */
this.eventManager_ = new shaka.util.EventManager();

this.eventManager_.listen(document, 'fullscreenchange', () => {
this.updateCaptions_(/* forceUpdate= */ true);
});
}


Expand Down Expand Up @@ -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;
}
}


Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit b426fe8

Please sign in to comment.