Skip to content

Commit

Permalink
Merge pull request #4864 from GAntoine/issue-4857
Browse files Browse the repository at this point in the history
Space bar plays/pauses music in queue view
  • Loading branch information
thornbill authored Oct 18, 2023
2 parents 0dbdc5d + 68362f4 commit 83ed83f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/controllers/playback/queue/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import RemoteControl from '../../../components/remotecontrol/remotecontrol';
import { playbackManager } from '../../../components/playback/playbackmanager';
import libraryMenu from '../../../scripts/libraryMenu';
import '../../../elements/emby-button/emby-button';

export default function (view) {
const remoteControl = new RemoteControl();
remoteControl.init(view, view.querySelector('.remoteControlContent'));

let currentPlayer;

function onKeyDown(e) {
if (e.keyCode === 32 && e.target.tagName !== 'BUTTON') {
playbackManager.playPause(currentPlayer);
e.preventDefault();
e.stopPropagation();
}
}

function releaseCurrentPlayer() {
const player = currentPlayer;
if (player) currentPlayer = null;
}

function bindToPlayer(player) {
if (player !== currentPlayer) {
releaseCurrentPlayer();
currentPlayer = player;
}
}

view.addEventListener('viewshow', function () {
libraryMenu.setTransparentMenu(true);
bindToPlayer(playbackManager.getCurrentPlayer());
document.addEventListener('keydown', onKeyDown);

if (remoteControl) {
remoteControl.onShow();
}
});

view.addEventListener('viewbeforehide', function () {
libraryMenu.setTransparentMenu(false);
document.removeEventListener('keydown', onKeyDown);
releaseCurrentPlayer();

if (remoteControl) {
remoteControl.destroy();
Expand Down

0 comments on commit 83ed83f

Please sign in to comment.