diff --git a/src/components/nowPlayingBar/nowPlayingBar.js b/src/components/nowPlayingBar/nowPlayingBar.js index c16b167d0d..c84a1ed9f3 100644 --- a/src/components/nowPlayingBar/nowPlayingBar.js +++ b/src/components/nowPlayingBar/nowPlayingBar.js @@ -252,6 +252,8 @@ function bindEvents(elem) { } }); + volumeSlider.addEventListener('wheel', handleVolumeScroll); + positionSlider.addEventListener('change', function () { if (currentPlayer) { const newPercent = parseFloat(this.value); @@ -708,6 +710,32 @@ function onVolumeChanged() { updatePlayerVolumeState(player.isMuted(), player.getVolume()); } +function handleVolumeKeyInput(e) { + e.preventDefault(); + e.stopPropagation(); + if (e.key === 'ArrowUp') { + handleVolumeChange(2); + } else if (e.key === 'ArrowDown') { + handleVolumeChange(-2); + } +} +function handleVolumeScroll(e) { + e.preventDefault(); + e.stopPropagation(); + if (e.deltaY < 0) { + handleVolumeChange(-2); + } else { + handleVolumeChange(2); + } +} + +function handleVolumeChange(change) { + volumeSlider.value = Math.max(0, Math.min(100, parseInt(volumeSlider.value, 10) + change)); + if (currentPlayer) { + currentPlayer.setVolume(parseInt(volumeSlider.value, 10)); + } +} + function refreshFromPlayer(player, type) { const state = playbackManager.getPlayerState(player); @@ -764,3 +792,5 @@ document.addEventListener('viewbeforeshow', function (e) { } } }); + +document.addEventListener('keydown', handleVolumeKeyInput);