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): adapt player height to control bar height in audioOnly mode #8579

Merged
merged 1 commit into from
May 3, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@
this.boundHandleTechTouchEnd_ = (e) => this.handleTechTouchEnd_(e);
this.boundHandleTechTap_ = (e) => this.handleTechTap_(e);

this.boundUpdatePlayerHeightOnAudioOnlyMode_ = (e) => this.updatePlayerHeightOnAudioOnlyMode_(e);

// default isFullscreen_ to false
this.isFullscreen_ = false;

Expand Down Expand Up @@ -395,6 +397,7 @@

// Init state audioOnlyCache_
this.audioOnlyCache_ = {
controlBarHeight: null,
playerHeight: null,
hiddenChildren: []
};
Expand Down Expand Up @@ -4496,6 +4499,17 @@
return !!this.isAudio_;
}

updatePlayerHeightOnAudioOnlyMode_() {
const controlBar = this.getChild('ControlBar');

if (!controlBar || this.audioOnlyCache_.controlBarHeight === controlBar.currentHeight()) {
return;

Check warning on line 4506 in src/js/player.js

View check run for this annotation

Codecov / codecov/patch

src/js/player.js#L4506

Added line #L4506 was not covered by tests
}

this.audioOnlyCache_.controlBarHeight = controlBar.currentHeight();
this.height(this.audioOnlyCache_.controlBarHeight);
}

enableAudioOnlyUI_() {
// Update styling immediately to show the control bar so we can get its height
this.addClass('vjs-audio-only-mode');
Expand All @@ -4519,6 +4533,9 @@
});

this.audioOnlyCache_.playerHeight = this.currentHeight();
this.audioOnlyCache_.controlBarHeight = controlBarHeight;

this.on('playerresize', this.boundUpdatePlayerHeightOnAudioOnlyMode_);

// Set the player height the same as the control bar
this.height(controlBarHeight);
Expand All @@ -4527,6 +4544,7 @@

disableAudioOnlyUI_() {
this.removeClass('vjs-audio-only-mode');
this.off('playerresize', this.boundUpdatePlayerHeightOnAudioOnlyMode_);

// Show player components that were previously hidden
this.audioOnlyCache_.hiddenChildren.forEach(child => child.show());
Expand Down
27 changes: 27 additions & 0 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3401,6 +3401,33 @@ QUnit.test('turning on audioPosterMode when audioOnlyMode is already on will tur
});
});

QUnit.test('player height should match control bar height when audioOnlyMode is enabled', function(assert) {
const player = TestHelpers.makePlayer({ responsive: true, width: 320, height: 240 });

player.trigger('ready');

player.audioOnlyMode(true).then(() => {
const initialPlayerHeight = player.currentHeight();

player.width(768);
player.el().style.fontSize = '20px';
player.trigger('playerresize');

assert.ok(initialPlayerHeight !== player.currentHeight(), 'player height is updated');
})
.then(() => player.audioOnlyMode(false))
.then(() => {
const initialPlayerHeight = player.currentHeight();

player.width(768);
player.el().style.fontSize = '20px';
player.trigger('playerresize');

assert.equal(player.currentHeight(), initialPlayerHeight, 'player height remains unchanged');
assert.ok(initialPlayerHeight !== player.controlBar.currentHeight(), 'player height is different from control bar height');
});
});

QUnit.test('player#load resets the media element to its initial state', function(assert) {
const player = TestHelpers.makePlayer({});

Expand Down