From 12078b80f3e89ef31d1532dfe7846623ab7b8a3e Mon Sep 17 00:00:00 2001 From: Alessandro Tassinari Date: Sun, 16 Mar 2025 00:20:34 +0100 Subject: [PATCH 1/2] Add space key functionality for playback control Implemented handling for the space key to toggle play/pause and adjust playback rate. Introduced a timeout mechanism to increase playback speed if the space key is held down for more than 500ms. Added corresponding keyup event listener to manage playback state effectively. --- src/controllers/playback/video/index.js | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index 8e43667e44..78cff40472 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -1214,6 +1214,10 @@ export default function (view) { } } + let spaceKeyTimeout; + let isSpaceKeyDown = false; + let isSpaceKeyHeld = false; + function onKeyDown(e) { clickedElement = e.target; @@ -1228,8 +1232,16 @@ export default function (view) { if (e.keyCode === 32) { if (e.target.tagName !== 'BUTTON' || !layoutManager.tv) { - playbackManager.playPause(currentPlayer); - showOsd(btnPlayPause); + if (!isSpaceKeyDown) { + isSpaceKeyDown = true; + isSpaceKeyHeld = false; + + spaceKeyTimeout = setTimeout(() => { + isSpaceKeyHeld = true; + playbackManager.setPlaybackRate(2, currentPlayer); + }, 500); + } + e.preventDefault(); e.stopPropagation(); // Trick Firefox with a null element to skip next click @@ -1430,6 +1442,27 @@ export default function (view) { } } + function onKeyUp(e) { + if (e.keyCode === 32) { + if (isSpaceKeyDown) { + if (isSpaceKeyHeld) { + playbackManager.setPlaybackRate(1, currentPlayer); + } else { + playbackManager.playPause(currentPlayer); + showOsd(osdBottomElement.querySelector('.btnPause')); + } + + if (spaceKeyTimeout) { + clearTimeout(spaceKeyTimeout); + spaceKeyTimeout = null; + } + + isSpaceKeyDown = false; + isSpaceKeyHeld = false; + } + } + } + function onKeyDownCapture() { resetIdle(); } @@ -1680,6 +1713,7 @@ export default function (view) { showOsd(); inputManager.on(window, onInputCommand); document.addEventListener('keydown', onKeyDown); + document.addEventListener('keyup', onKeyUp); dom.addEventListener(document, 'keydown', onKeyDownCapture, { capture: true, passive: true @@ -1723,6 +1757,7 @@ export default function (view) { } document.removeEventListener('keydown', onKeyDown); + document.removeEventListener('keyup', onKeyUp); dom.removeEventListener(document, 'keydown', onKeyDownCapture, { capture: true, passive: true From 2df3a4a8ca9ed0974a72634eb905f1f132fd67d9 Mon Sep 17 00:00:00 2001 From: Alessandro Tassinari Date: Sun, 16 Mar 2025 00:25:35 +0100 Subject: [PATCH 2/2] Add Ale4224 to the list of contributors --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8737fc166b..0828ee2c86 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -96,6 +96,7 @@ - [K. Kyle Puchkov](https://github.com/kepper104) - [ItsAllAboutTheCode](https://github.com/ItsAllAboutTheCode) - [Jxiced](https://github.com/Jxiced) +- [Ale4224](https://github.com/Ale4224) ## Emby Contributors