From 8006d62f55627db1d066f2dcf6f7f29f852d5e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Thomas?= Date: Thu, 16 Jun 2016 00:30:31 +0200 Subject: [PATCH] Restored most keyboard shortcuts from Subsonic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: François-Xavier Thomas --- .../src/main/webapp/WEB-INF/jsp/head.jsp | 28 ++++++ .../src/main/webapp/WEB-INF/jsp/playQueue.jsp | 99 +++++++++++++++++-- .../src/main/webapp/WEB-INF/jsp/top.jsp | 8 ++ .../src/main/webapp/script/mousetrap-1.6.0.js | 11 +++ 4 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 libresonic-main/src/main/webapp/script/mousetrap-1.6.0.js diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/head.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/head.jsp index b14d62a2..5331458b 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/head.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/head.jsp @@ -10,3 +10,31 @@ Libresonic + + + diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp index 7f539ddd..7e6cb2b9 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp @@ -37,6 +37,7 @@ var songs = null; var currentStreamUrl = null; var repeatEnabled = false; + var isVisible = ${model.autoHidePlayQueue ? 'false' : 'true'}; var CastPlayer = new CastPlayer(); var ignore = false; @@ -86,17 +87,30 @@ getPlayQueue(); } + function onHidePlayQueue() { + setFrameHeight(50); + isVisible = false; + } + + function onShowPlayQueue() { + var height = $("body").height() + 25; + height = Math.min(height, window.top.innerHeight * 0.8); + setFrameHeight(height); + isVisible = true; + } + + function onTogglePlayQueue() { + if (isVisible) onHidePlayQueue(); + else onShowPlayQueue(); + } + function initAutoHide() { $(window).mouseleave(function (event) { - if (event.clientY < 30) { - setFrameHeight(50); - } + if (event.clientY < 30) onHidePlayQueue(); }); $(window).mouseenter(function () { - var height = $("body").height() + 25; - height = Math.min(height, window.top.innerHeight * 0.8); - setFrameHeight(height); + onShowPlayQueue(); }); } @@ -155,12 +169,56 @@ playQueueService.clear(playQueueCallback); } } + + /** + * Start playing from the current playlist + */ function onStart() { - playQueueService.start(playQueueCallback); + if (CastPlayer.castSession) { + CastPlayer.playCast(); + } else if (jwplayer()) { + if (jwplayer().getState() == "IDLE") { + skip(0); + } else if (jwplayer().getState() == "PAUSED") { + jwplayer().play(true); + } + } else { + playQueueService.start(playQueueCallback); + } } + + /** + * Pause playing + */ function onStop() { - playQueueService.stop(playQueueCallback); + if (CastPlayer.castSession) { + CastPlayer.pauseCast(); + } else if (jwplayer()) { + jwplayer().pause(true); + } else { + playQueueService.stop(playQueueCallback); + } } + + /** + * Toggle play/pause + * + * FIXME: Only works for the Web player for now + */ + function onToggleStartStop() { + var playing = false; + if (CastPlayer.castSession) { + playing = CastPlayer.mediaSession && CastPlayer.mediaSession.playerState == chrome.cast.media.PlayerState.PLAYING; + } else if (jwplayer()) { + playing = jwplayer().getState() == "PLAYING"; + } else { + // FIXME for playQueueService + } + + if (playing) onStop(); + else onStart(); + } + function onGain(gain) { playQueueService.setGain(gain); } @@ -172,6 +230,24 @@ var value = parseInt($("#castVolume").slider("option", "value")); CastPlayer.setCastVolume(value / 100, false); } + + /** + * Increase or decrease volume by a certain amount + * + * @param amount to add or remove from the current volume + */ + function onGainAdd(gain) { + if (CastPlayer.castSession) { + var volume = parseInt($("#castVolume").slider("option", "value")) + gain; + $("#castVolume").slider("option", "value", volume); + } else if (jwplayer()) { + jwplayer().setVolume(jwplayer().getVolume() + gain); + } else { + var value = parseInt($("#jukeboxVolume").slider("option", "value")); + $("#jukeboxVolume").slider("option", "value", volume); + } + } + function onSkip(index) { @@ -188,10 +264,10 @@ if (wrap) { index = index % songs.length; } - skip(index); + onSkip(index); } function onPrevious() { - skip(parseInt(getCurrentSongIndex()) - 1); + onSkip(parseInt(getCurrentSongIndex()) - 1); } function onPlay(id) { playQueueService.play(id, playQueueCallback); @@ -235,6 +311,9 @@ function onStar(index) { playQueueService.toggleStar(index, playQueueCallback); } + function onStarCurrent() { + onStar(getCurrentSongIndex()); + } function onRemove(index) { playQueueService.remove(index, playQueueCallback); } diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/top.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/top.jsp index 7eeb095d..28791bfa 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/top.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/top.jsp @@ -10,6 +10,7 @@