Skip to content

Commit 720d888

Browse files
trflynn89awesomekling
authored andcommitted
LibWeb: Allow changing media volume with keyboard controls
This allows increasing and decreasing the media volume by 10% with the up and down arrow keys, respectively. This also allows toggling the mute state with the M key.
1 parent 6a5229c commit 720d888

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,24 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::handle_keydown(Badge<Web::EventHandl
18851885
break;
18861886
}
18871887

1888+
case KeyCode::Key_Up:
1889+
case KeyCode::Key_Down: {
1890+
static constexpr double volume_change_per_key_press = 0.1;
1891+
auto volume = this->volume();
1892+
1893+
if (key == KeyCode::Key_Up)
1894+
volume = min(1.0, volume + volume_change_per_key_press);
1895+
else
1896+
volume = max(0.0, volume - volume_change_per_key_press);
1897+
1898+
TRY(set_volume(volume));
1899+
break;
1900+
}
1901+
1902+
case KeyCode::Key_M:
1903+
set_muted(!muted());
1904+
break;
1905+
18881906
default:
18891907
break;
18901908
}

0 commit comments

Comments
 (0)