Skip to content

Commit

Permalink
Handling removal of songs only on the client side to prevent sideeffects
Browse files Browse the repository at this point in the history
  • Loading branch information
Faeb35 committed Jun 21, 2020
1 parent 1cc56bd commit 15e2b32
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
// Initialize the Cast player (ChromeCast support)
var CastPlayer = new CastPlayer();
// silent and empty sound, set when audio media player is stopped
const silentSound = 'data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA';
function init() {
<c:if test="${model.autoHide}">initAutoHide();</c:if>
Expand Down Expand Up @@ -253,6 +256,7 @@
ok = confirm("<fmt:message key="playlist.confirmclear"/>");
</c:if>
if (ok) {
onStopMediaElementPlayer();
playQueueService.clear(playQueueCallback);
}
}
Expand Down Expand Up @@ -288,6 +292,29 @@
}
}
/**
* Stop HTML audio player and set silet audio as src attribute
*/
function onStopMediaElementPlayer() {
var mediaElementPlayer = getMediaElementPlayer();
if (mediaElementPlayer) {
mediaElementPlayer.pause();
mediaElementPlayer.currentTime = 0;
setTimeout(function() {
mediaElementPlayer.src = silentSound;
playQueueService.stop(playQueueCallback);
}, 100);
}
}
function isMediaElementPlayerStopped() {
var mediaElementPlayer = getMediaElementPlayer();
if (mediaElementPlayer) {
return mediaElementPlayer.src == silentSound;
}
}
/**
* Toggle play/pause
*
Expand Down Expand Up @@ -427,6 +454,9 @@
onStar(getCurrentSongIndex());
}
function onRemove(index) {
if (index == getCurrentSongIndex()) {
onStopMediaElementPlayer();
}
playQueueService.remove(index, playQueueCallback);
}
function onRemoveSelected() {
Expand All @@ -436,6 +466,9 @@
var index = i + 1;
if ($("#songIndex" + index).is(":checked")) {
indexes[counter++] = i;
if (i == getCurrentSongIndex()) {
onStopMediaElementPlayer();
}
}
}
playQueueService.removeMany(indexes, playQueueCallback);
Expand Down Expand Up @@ -509,7 +542,11 @@
function playQueueCallback(playQueue) {
songs = playQueue.entries;
currentSongIndex = playQueue.index;
if (isMediaElementPlayerStopped()) {
currentSongIndex = -1;
} else {
currentSongIndex = playQueue.index;
}
repeatEnabled = playQueue.repeatEnabled;
shuffleRadioEnabled = playQueue.shuffleRadioEnabled;
internetRadioEnabled = playQueue.internetRadioEnabled;
Expand Down

0 comments on commit 15e2b32

Please sign in to comment.