Add 'add to play queue' actions to playlist pages (#1226)

master
François-Xavier Thomas 5 years ago
parent 2d30a37208
commit d7c5e3ab60
  1. 29
      airsonic-main/src/main/java/org/airsonic/player/ajax/PlayQueueService.java
  2. 5
      airsonic-main/src/main/webapp/WEB-INF/jsp/coverArt.jsp
  3. 3
      airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp
  4. 6
      airsonic-main/src/main/webapp/WEB-INF/jsp/playlist.jsp

@ -250,6 +250,33 @@ public class PlayQueueService {
return doPlayInternetRadio(request, player, radio).setStartPlayerAt(0); return doPlayInternetRadio(request, player, radio).setStartPlayerAt(0);
} }
/**
* @param index Start playing at this index, or play whole playlist if {@code null}.
*/
public PlayQueueInfo addPlaylist(int id, Integer index) throws Exception {
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
HttpServletResponse response = WebContextFactory.get().getHttpServletResponse();
String username = securityService.getCurrentUsername(request);
boolean queueFollowingSongs = settingsService.getUserSettings(username).isQueueFollowingSongs();
List<MediaFile> files = playlistService.getFilesInPlaylist(id, true);
if (!files.isEmpty() && index != null) {
if (queueFollowingSongs) {
files = files.subList(index, files.size());
} else {
files = Arrays.asList(files.get(index));
}
}
// Remove non-present files
files.removeIf(file -> !file.isPresent());
// Add to the play queue
int[] ids = files.stream().mapToInt(f -> f.getId()).toArray();
return doAdd(request, response, ids, index);
}
/** /**
* @param index Start playing at this index, or play whole playlist if {@code null}. * @param index Start playing at this index, or play whole playlist if {@code null}.
*/ */
@ -271,6 +298,8 @@ public class PlayQueueService {
// Remove non-present files // Remove non-present files
files.removeIf(file -> !file.isPresent()); files.removeIf(file -> !file.isPresent());
// Play now
Player player = getCurrentPlayer(request, response); Player player = getCurrentPlayer(request, response);
return doPlay(request, player, files).setStartPlayerAt(0); return doPlay(request, player, files).setStartPlayerAt(0);
} }

@ -76,7 +76,7 @@ PARAMETERS
style="position: relative; top: 8px; left: 8px; z-index: 2; display:none" > style="position: relative; top: 8px; left: 8px; z-index: 2; display:none" >
</div> </div>
<c:if test="${not empty param.albumId}"> <c:if test="${not empty param.albumId or not empty param.playlistId}">
<div style="position: relative; width: 0; height: 0"> <div style="position: relative; width: 0; height: 0">
<img alt="Add overlay" src="<spring:theme code='addOverlayImage'/>" id="${addId}" <img alt="Add overlay" src="<spring:theme code='addOverlayImage'/>" id="${addId}"
style="position: relative; top: 8px; left: 48px; z-index: 2; display:none" > style="position: relative; top: 8px; left: 48px; z-index: 2; display:none" >
@ -154,5 +154,8 @@ PARAMETERS
<c:if test="${not empty param.albumId}"> <c:if test="${not empty param.albumId}">
top.playQueue.onAdd(${param.albumId}); top.playQueue.onAdd(${param.albumId});
</c:if> </c:if>
<c:if test="${not empty param.playlistId}">
top.playQueue.onAddPlaylist(${param.playlistId});
</c:if>
}); });
</script> </script>

@ -380,6 +380,9 @@
function onAddNext(id) { function onAddNext(id) {
playQueueService.addAt(id, getCurrentSongIndex() + 1, playQueueCallback); playQueueService.addAt(id, getCurrentSongIndex() + 1, playQueueCallback);
} }
function onAddPlaylist(id, index) {
playQueueService.addPlaylist(id, index, playQueueCallback);
}
function onShuffle() { function onShuffle() {
playQueueService.shuffle(playQueueCallback); playQueueService.shuffle(playQueueCallback);
} }

@ -134,6 +134,9 @@
function onPlayAll() { function onPlayAll() {
top.playQueue.onPlayPlaylist(playlist.id); top.playQueue.onPlayPlaylist(playlist.id);
} }
function onAddAll() {
top.playQueue.onAddPlaylist(playlist.id);
}
function onAdd(index) { function onAdd(index) {
top.playQueue.onAdd(songs[index].id); top.playQueue.onAdd(songs[index].id);
$().toastmessage('showSuccessToast', '<fmt:message key="main.addlast.toast"/>') $().toastmessage('showSuccessToast', '<fmt:message key="main.addlast.toast"/>')
@ -184,7 +187,8 @@
<h1><a href="playlists.view"><fmt:message key="left.playlists"/></a> &raquo; <span id="name">${fn:escapeXml(model.playlist.name)}</span></h1> <h1><a href="playlists.view"><fmt:message key="left.playlists"/></a> &raquo; <span id="name">${fn:escapeXml(model.playlist.name)}</span></h1>
<h2> <h2>
<span class="header"><a href="javascript:void(0)" onclick="onPlayAll();"><fmt:message key="common.play"/></a></span> <span class="header"><a href="javascript:onPlayAll()"><fmt:message key="common.play"/></a></span> |
<span class="header"><a href="javascript:onAddAll()"><fmt:message key="main.addall"/></a></span>
<c:if test="${model.user.downloadRole}"> <c:if test="${model.user.downloadRole}">
<c:url value="download.view" var="downloadUrl"><c:param name="playlist" value="${model.playlist.id}"/></c:url> <c:url value="download.view" var="downloadUrl"><c:param name="playlist" value="${model.playlist.id}"/></c:url>

Loading…
Cancel
Save