Skip to content

Commit

Permalink
fix: keep minimum volume after unmuting above 0.1 (#4227)
Browse files Browse the repository at this point in the history
If, when unmuting, the last volume is below 0.1, force it to be 0.1.

Fixes #4054.
  • Loading branch information
kevinlitchfield authored and gkatsev committed Mar 24, 2017
1 parent 7d12c9e commit 16c1e0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/js/control-bar/mute-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class MuteToggle extends Button {
const lastVolume = this.player_.lastVolume_();

if (vol === 0) {
this.player_.volume(lastVolume);
const volumeToSet = lastVolume < 0.1 ? 0.1 : lastVolume;

this.player_.volume(volumeToSet);
this.player_.muted(false);
} else {
this.player_.muted(this.player_.muted() ? false : true);
Expand Down
15 changes: 14 additions & 1 deletion test/unit/controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ if (Html5.isSupported()) {
assert.equal(player.muted(), false, 'muted is set to false');
});

QUnit.test('Clicking MuteToggle when volume is 0, lastVolume is less than 0.1, and muted is true sets volume to 0.1 and muted to false', function(assert) {
const player = TestHelpers.makePlayer({ techOrder: ['html5'] });
const muteToggle = new MuteToggle(player);

player.volume(0);
player.muted(true);
player.lastVolume_(0.05);

muteToggle.handleClick();

assert.equal(player.volume(), 0.1, 'since lastVolume is less than 0.1, volume is set to 0.1');
assert.equal(player.muted(), false, 'muted is set to false');
});

QUnit.test('ARIA value of VolumeBar should start at 100', function(assert) {
const player = TestHelpers.makePlayer({ techOrder: ['html5'] });
const volumeBar = new VolumeBar(player);
Expand Down Expand Up @@ -179,5 +193,4 @@ if (Html5.isSupported()) {
assert.equal(player.muted(), true, 'Muted is true');
assert.equal(volumeBar.el_.getAttribute('aria-valuenow'), 0, 'ARIA value of VolumeBar is 0');
});

}

0 comments on commit 16c1e0a

Please sign in to comment.