Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(player): Ensure fluid works when dimensions not initially known #7023

Merged
merged 1 commit into from
Jan 6, 2021
Merged
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
8 changes: 4 additions & 4 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class Player extends Component {
}

if (this.fluid_) {
this.on('playerreset', this.updateStyleEl_);
this.on(['playerreset', 'resize'], this.updateStyleEl_);
}
// We also want to pass the original player options to each component and plugin
// as well so they don't need to reach back into the player for options later.
Expand Down Expand Up @@ -912,13 +912,13 @@ class Player extends Component {
this.fluid_ = !!bool;

if (isEvented(this)) {
this.off('playerreset', this.updateStyleEl_);
this.off(['playerreset', 'resize'], this.updateStyleEl_);
}
if (bool) {
this.addClass('vjs-fluid');
this.fill(false);
addEventedCallback(function() {
this.on('playerreset', this.updateStyleEl_);
addEventedCallback(this, () => {
this.on(['playerreset', 'resize'], this.updateStyleEl_);
});
} else {
this.removeClass('vjs-fluid');
Expand Down
39 changes: 39 additions & 0 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,45 @@ QUnit.test('should default to 16:9 when fluid', function(assert) {
player.dispose();
});

QUnit.test('should resize fluid player on resize', function(assert) {
const player = TestHelpers.makePlayer({fluid: true});
let ratio = player.currentHeight() / player.currentWidth();

// account for some rounding of 0.5625 up to 0.563
assert.ok(((ratio >= 0.562) && (ratio <= 0.563)), 'fluid player without dimensions defaults to 16:9');

player.tech_.videoWidth = () => 100;
player.tech_.videoHeight = () => 50;

player.trigger('resize');

this.clock.tick(1);

ratio = player.currentHeight() / player.currentWidth();

assert.ok(ratio === 0.5, 'player aspect ratio changed on resize event');

player.dispose();
});

QUnit.test('should resize fluid player on resize if fluid enabled post initialisation', function(assert) {
const player = TestHelpers.makePlayer({fluid: false});

player.tech_.videoWidth = () => 100;
player.tech_.videoHeight = () => 30;

player.fluid(true);
player.trigger('resize');

this.clock.tick(1);

const ratio = player.currentHeight() / player.currentWidth();

assert.ok(ratio === 0.3, 'player aspect ratio changed on resize event');

player.dispose();
});

QUnit.test('should set fluid to true if element has vjs-fluid class', function(assert) {
const tag = TestHelpers.makeTag();

Expand Down