mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
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.
This commit is contained in:
parent
ccf201739e
commit
12078b80f3
1 changed files with 37 additions and 2 deletions
|
@ -1214,6 +1214,10 @@ export default function (view) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let spaceKeyTimeout;
|
||||||
|
let isSpaceKeyDown = false;
|
||||||
|
let isSpaceKeyHeld = false;
|
||||||
|
|
||||||
function onKeyDown(e) {
|
function onKeyDown(e) {
|
||||||
clickedElement = e.target;
|
clickedElement = e.target;
|
||||||
|
|
||||||
|
@ -1228,8 +1232,16 @@ export default function (view) {
|
||||||
|
|
||||||
if (e.keyCode === 32) {
|
if (e.keyCode === 32) {
|
||||||
if (e.target.tagName !== 'BUTTON' || !layoutManager.tv) {
|
if (e.target.tagName !== 'BUTTON' || !layoutManager.tv) {
|
||||||
playbackManager.playPause(currentPlayer);
|
if (!isSpaceKeyDown) {
|
||||||
showOsd(btnPlayPause);
|
isSpaceKeyDown = true;
|
||||||
|
isSpaceKeyHeld = false;
|
||||||
|
|
||||||
|
spaceKeyTimeout = setTimeout(() => {
|
||||||
|
isSpaceKeyHeld = true;
|
||||||
|
playbackManager.setPlaybackRate(2, currentPlayer);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
// Trick Firefox with a null element to skip next click
|
// 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() {
|
function onKeyDownCapture() {
|
||||||
resetIdle();
|
resetIdle();
|
||||||
}
|
}
|
||||||
|
@ -1680,6 +1713,7 @@ export default function (view) {
|
||||||
showOsd();
|
showOsd();
|
||||||
inputManager.on(window, onInputCommand);
|
inputManager.on(window, onInputCommand);
|
||||||
document.addEventListener('keydown', onKeyDown);
|
document.addEventListener('keydown', onKeyDown);
|
||||||
|
document.addEventListener('keyup', onKeyUp);
|
||||||
dom.addEventListener(document, 'keydown', onKeyDownCapture, {
|
dom.addEventListener(document, 'keydown', onKeyDownCapture, {
|
||||||
capture: true,
|
capture: true,
|
||||||
passive: true
|
passive: true
|
||||||
|
@ -1723,6 +1757,7 @@ export default function (view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.removeEventListener('keydown', onKeyDown);
|
document.removeEventListener('keydown', onKeyDown);
|
||||||
|
document.removeEventListener('keyup', onKeyUp);
|
||||||
dom.removeEventListener(document, 'keydown', onKeyDownCapture, {
|
dom.removeEventListener(document, 'keydown', onKeyDownCapture, {
|
||||||
capture: true,
|
capture: true,
|
||||||
passive: true
|
passive: true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue