From 0ce7b585e383274f16c3d7d676520788596ccd41 Mon Sep 17 00:00:00 2001 From: nwhitmont <3075047+nwhitmont@users.noreply.github.com> Date: Sun, 26 May 2024 20:46:00 -0700 Subject: [PATCH 1/3] add event handler to change volume on scroll wheel up/down --- src/components/nowPlayingBar/nowPlayingBar.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/nowPlayingBar/nowPlayingBar.js b/src/components/nowPlayingBar/nowPlayingBar.js index b73ce0d888..169e9eba95 100644 --- a/src/components/nowPlayingBar/nowPlayingBar.js +++ b/src/components/nowPlayingBar/nowPlayingBar.js @@ -250,6 +250,20 @@ function bindEvents(elem) { } }); + volumeSlider.addEventListener('wheel', (e) => { + e.preventDefault(); + // don't scroll the whole page + e.stopPropagation(); + if (e.deltaY < 0) { + volumeSlider.value = Math.min(parseInt(volumeSlider.value, 10) + 2, 100); + } else { // Scroll down + volumeSlider.value = Math.max(parseInt(volumeSlider.value, 10) - 2, 0); + } + if (currentPlayer) { + currentPlayer.setVolume(parseInt(volumeSlider.value, 10)); + } + }); + positionSlider.addEventListener('change', function () { if (currentPlayer) { const newPercent = parseFloat(this.value); From c2f89d191b3cb7861ec7c389a5f45b4ae1afbf9d Mon Sep 17 00:00:00 2001 From: nwhitmont <3075047+nwhitmont@users.noreply.github.com> Date: Sun, 26 May 2024 21:38:58 -0700 Subject: [PATCH 2/3] add up/down key event handler, refactor --- src/components/nowPlayingBar/nowPlayingBar.js | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/components/nowPlayingBar/nowPlayingBar.js b/src/components/nowPlayingBar/nowPlayingBar.js index 169e9eba95..660a3525d6 100644 --- a/src/components/nowPlayingBar/nowPlayingBar.js +++ b/src/components/nowPlayingBar/nowPlayingBar.js @@ -250,19 +250,7 @@ function bindEvents(elem) { } }); - volumeSlider.addEventListener('wheel', (e) => { - e.preventDefault(); - // don't scroll the whole page - e.stopPropagation(); - if (e.deltaY < 0) { - volumeSlider.value = Math.min(parseInt(volumeSlider.value, 10) + 2, 100); - } else { // Scroll down - volumeSlider.value = Math.max(parseInt(volumeSlider.value, 10) - 2, 0); - } - if (currentPlayer) { - currentPlayer.setVolume(parseInt(volumeSlider.value, 10)); - } - }); + volumeSlider.addEventListener('wheel', handleVolumeScroll); positionSlider.addEventListener('change', function () { if (currentPlayer) { @@ -780,6 +768,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); @@ -836,3 +850,5 @@ document.addEventListener('viewbeforeshow', function (e) { } } }); + +document.addEventListener('keydown', handleVolumeKeyInput); From ffb6eba99513ad5bd8aa0055809adba0ef2dd0a7 Mon Sep 17 00:00:00 2001 From: nwhitmont <3075047+nwhitmont@users.noreply.github.com> Date: Mon, 27 May 2024 00:17:15 -0700 Subject: [PATCH 3/3] fix scroll direction --- src/components/nowPlayingBar/nowPlayingBar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/nowPlayingBar/nowPlayingBar.js b/src/components/nowPlayingBar/nowPlayingBar.js index 660a3525d6..1a1ffc487e 100644 --- a/src/components/nowPlayingBar/nowPlayingBar.js +++ b/src/components/nowPlayingBar/nowPlayingBar.js @@ -781,9 +781,9 @@ function handleVolumeScroll(e) { e.preventDefault(); e.stopPropagation(); if (e.deltaY < 0) { - handleVolumeChange(2); - } else { handleVolumeChange(-2); + } else { + handleVolumeChange(2); } }