From 21eff917b6878970068dd3b432bac67f896070b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Thomas?= Date: Sat, 5 Jan 2019 21:27:45 +0100 Subject: [PATCH] PlayQueue: Fix broken keyboard shortcuts Using the "space" key to resume playback, as well as +/- to increase/decrease volume, were not working properly. --- .../src/main/webapp/WEB-INF/jsp/playQueue.jsp | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp b/airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp index 20815780..289a9724 100644 --- a/airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp +++ b/airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp @@ -167,15 +167,17 @@ } /** - * Start playing from the current playlist + * Start/resume playing from the current playlist */ function onStart() { if (CastPlayer.castSession) { CastPlayer.playCast(); } else if ($('#audioPlayer').get(0)) { - var audioPlayer = $('#audioPlayer'); - if(audioPlayer.paused) { - skip(0, audioPlayer.currentTime); + if ($('#audioPlayer').get(0).src) { + $('#audioPlayer').get(0).play(); // Resume playing if the player was paused + } + else { + skip(0); // Start the first track if the player was not yet loaded } } else { playQueueService.start(playQueueCallback); @@ -205,8 +207,9 @@ var playing = CastPlayer.mediaSession && CastPlayer.mediaSession.playerState == chrome.cast.media.PlayerState.PLAYING; if (playing) onStop(); else onStart(); - } else if ($('#audioPlayer')) { - if (!$('#audioPlayer').get(0).paused) onStop(); + } else if ($('#audioPlayer').get(0)) { + var playing = $("#audioPlayer").get(0).paused != null && !$("#audioPlayer").get(0).paused; + if (playing) onStop(); else onStart(); } else { playQueueService.toggleStartStop(playQueueCallback); @@ -237,11 +240,11 @@ if (volume < 0) volume = 0; CastPlayer.setCastVolume(volume / 100, false); $("#castVolume").slider("option", "value", volume); // Need to update UI - } else if ($('#audioPlayer')) { - var volume = parseInt($('#audioPlayer').get(0).volume) + gain; + } else if ($('#audioPlayer').get(0)) { + var volume = parseFloat($('#audioPlayer').get(0).volume)*100 + gain; if (volume > 100) volume = 100; if (volume < 0) volume = 0; - $('#audioPlayer').get(0).volume = volume; + $('#audioPlayer').get(0).volume = volume / 100; } else { var volume = parseInt($("#jukeboxVolume").slider("option", "value")) + gain; if (volume > 100) volume = 100; @@ -360,7 +363,7 @@ playQueueService.sortByAlbum(playQueueCallback); } function onSavePlayQueue() { - var positionMillis = $('#audioPlayer') ? Math.round(1000.0 * $('#audioPlayer').get(0).currentTime) : 0; + var positionMillis = $('#audioPlayer').get(0) ? Math.round(1000.0 * $('#audioPlayer').get(0).currentTime) : 0; playQueueService.savePlayQueue(getCurrentSongIndex(), positionMillis); $().toastmessage("showSuccessToast", ""); } @@ -542,10 +545,13 @@ if (CastPlayer.castSession) { CastPlayer.loadCastMedia(song, position); } else { - $('#audioPlayer').get(0).src = song.streamUrl; - $('#audioPlayer').get(0).load(); + if ($('#audioPlayer').get(0).src != song.streamUrl) { + $('#audioPlayer').get(0).src = song.streamUrl; + $('#audioPlayer').get(0).load(); + console.log(song.streamUrl); + } + $('#audioPlayer').get(0).currentTime = position ? position : 0; $('#audioPlayer').get(0).play(); - console.log(song.streamUrl); } updateWindowTitle(song); @@ -689,7 +695,7 @@
-