Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/js/tracks/text-track-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,10 @@ class TextTrackDisplay extends Component {
* @listens Player#useractive
* @listens Player#userinactive
*/
updateDisplay() {
updateDisplay(event) {
const tracks = this.player_.textTracks();
const allowMultipleShowingTracks = this.options_.allowMultipleShowingTracks;
const forceCueRecompute = event && event.type === 'playerresize';

this.clearDisplay();

Expand All @@ -290,7 +291,7 @@ class TextTrackDisplay extends Component {
}
showingTracks.push(track);
}
this.updateForTrack(showingTracks);
this.updateForTrack(showingTracks, forceCueRecompute);
return;
}

Expand Down Expand Up @@ -318,12 +319,12 @@ class TextTrackDisplay extends Component {
if (this.getAttribute('aria-live') !== 'off') {
this.setAttribute('aria-live', 'off');
}
this.updateForTrack(captionsSubtitlesTrack);
this.updateForTrack(captionsSubtitlesTrack, forceCueRecompute);
} else if (descriptionsTrack) {
if (this.getAttribute('aria-live') !== 'assertive') {
this.setAttribute('aria-live', 'assertive');
}
this.updateForTrack(descriptionsTrack);
this.updateForTrack(descriptionsTrack, forceCueRecompute);
}

if (!(window.CSS !== undefined && window.CSS.supports('inset', '10px'))) {
Expand Down Expand Up @@ -485,7 +486,7 @@ class TextTrackDisplay extends Component {
* @param {TextTrack|TextTrack[]} tracks
* Text track object or text track array to be added to the list.
*/
updateForTrack(tracks) {
updateForTrack(tracks, forceCueRecompute = false) {
if (!Array.isArray(tracks)) {
tracks = [tracks];
}
Expand All @@ -503,7 +504,13 @@ class TextTrackDisplay extends Component {
const track = tracks[i];

for (let j = 0; j < track.activeCues.length; ++j) {
cues.push(track.activeCues[j]);
const cue = track.activeCues[j];

if (forceCueRecompute && cue) {
cue.hasBeenReset = true;
}

cues.push(cue);
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/unit/tracks/text-track-display.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ QUnit.test('shows the default caption track first', function(assert) {
});

if (!Html5.supportsNativeTextTracks()) {
QUnit.test('playerresize forces cue recompute on updateForTrack', function(assert) {
const player = TestHelpers.makePlayer();
const textTrackDisplay = player.textTrackDisplay;
const updateForTrackSpy = sinon.spy(textTrackDisplay, 'updateForTrack');
const showingTrack = {
mode: 'showing',
kind: 'captions',
activeCues: []
};

textTrackDisplay.clearDisplay = () => '';
sinon.stub(player, 'textTracks').returns([showingTrack]);

textTrackDisplay.updateDisplay({type: 'playerresize'});

assert.ok(updateForTrackSpy.calledOnce, 'updateForTrack was called');
assert.strictEqual(updateForTrackSpy.firstCall.args[1], true, 'cue recompute flag is true on playerresize');

updateForTrackSpy.restore();
player.textTracks.restore();
player.dispose();
});

QUnit.test('text track display should attach screen orientation change event handler', function(assert) {
const oldScreen = window.screen;
const removeHandlerSpy = sinon.spy();
Expand Down
Loading