Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Fix issue multiple songs marked as current causing loop #1759

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class PlayQueueInfo {

private final List<Entry> entries;
private final int index;
private final boolean stopEnabled;
private final boolean repeatEnabled;
private final boolean shuffleRadioEnabled;
Expand All @@ -40,8 +41,9 @@ public class PlayQueueInfo {
private int startPlayerAt = -1;
private long startPlayerAtPosition; // millis

public PlayQueueInfo(List<Entry> entries, boolean stopEnabled, boolean repeatEnabled, boolean shuffleRadioEnabled, boolean internetRadioEnabled, boolean sendM3U, float gain) {
public PlayQueueInfo(List<Entry> entries, int index, boolean stopEnabled, boolean repeatEnabled, boolean shuffleRadioEnabled, boolean internetRadioEnabled, boolean sendM3U, float gain) {
this.entries = entries;
this.index = index;
this.stopEnabled = stopEnabled;
this.repeatEnabled = repeatEnabled;
this.shuffleRadioEnabled = shuffleRadioEnabled;
Expand All @@ -54,6 +56,10 @@ public List<Entry> getEntries() {
return entries;
}

public int getIndex() {
return index;
}

public String getDurationAsString() {
int durationSeconds = 0;
for (Entry entry : entries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ private PlayQueueInfo convert(HttpServletRequest request, Player player, boolean
entries = convertMediaFileList(request, player);
}

int index = player.getPlayQueue().getIndex();
boolean isCurrentPlayer = player.getIpAddress() != null && player.getIpAddress().equals(request.getRemoteAddr());
boolean isStopEnabled = playQueue.getStatus() == PlayQueue.Status.PLAYING && !player.isExternalWithPlaylist();
boolean m3uSupported = player.isExternal() || player.isExternalWithPlaylist();
Expand All @@ -703,6 +704,7 @@ private PlayQueueInfo convert(HttpServletRequest request, Player player, boolean

return new PlayQueueInfo(
entries,
index,
isStopEnabled,
playQueue.isRepeatEnabled(),
playQueue.isShuffleRadioEnabled(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ public void handleRequest(HttpServletRequest request, HttpServletResponse respon
return;
}

// Update the index of the currently playing media file. At
// this point we haven't yet modified the play queue to support
// multiple streams, so the current play queue is the real one.
int currentIndex = player.getPlayQueue().getFiles().indexOf(file);
player.getPlayQueue().setIndex(currentIndex);

// Create a new, fake play queue that only contains the
// currently playing media file, in case multiple streams want
// to use the same player.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.airsonic.player.domain;

import org.airsonic.player.service.InternetRadioService;
import org.apache.commons.lang.StringUtils;

import java.util.*;
Expand All @@ -37,6 +38,7 @@ public class PlayQueue {

private RandomSearchCriteria randomSearchCriteria;
private InternetRadio internetRadio;
private InternetRadioService internetRadioService = new InternetRadioService();

/**
* The index of the current song, or -1 is the end of the playlist is reached.
Expand Down Expand Up @@ -129,7 +131,11 @@ public synchronized void next() {
* @return The number of songs in the playlists.
*/
public synchronized int size() {
return files.size();
if (internetRadio == null) {
return files.size();
} else {
return internetRadioService.getInternetRadioSources(internetRadio).size();
}
}

/**
Expand Down
17 changes: 8 additions & 9 deletions airsonic-main/src/main/webapp/WEB-INF/jsp/playQueue.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
// Is the play queue visible? (Initially hidden if set to "auto-hide" in the settings)
var isVisible = ${model.autoHide ? 'false' : 'true'};

// initialize index of the song currently played
var currentSongIndex = -1;

// Initialize the Cast player (ChromeCast support)
var CastPlayer = new CastPlayer();

Expand Down Expand Up @@ -352,9 +355,9 @@
if (isJavaJukeboxPresent()) {
updateJavaJukeboxPlayerControlBar(songs[index]);
}
playQueueService.skip(index, playQueueCallback);
</c:otherwise>
</c:choose>
playQueueService.skip(index, playQueueCallback);
}
function onNext(wrap) {
var index = parseInt(getCurrentSongIndex()) + 1;
Expand Down Expand Up @@ -506,6 +509,7 @@

function playQueueCallback(playQueue) {
songs = playQueue.entries;
currentSongIndex = playQueue.index;
repeatEnabled = playQueue.repeatEnabled;
shuffleRadioEnabled = playQueue.shuffleRadioEnabled;
internetRadioEnabled = playQueue.internetRadioEnabled;
Expand Down Expand Up @@ -598,7 +602,7 @@
$("#songIndex" + id).hide();
}

if ($("#currentImage" + id) && song.streamUrl == currentStreamUrl) {
if (i == currentSongIndex && song.streamUrl == currentStreamUrl && $("#currentImage" + id)) {
$("#currentImage" + id).show();
if (isJavaJukeboxPresent()) {
updateJavaJukeboxPlayerControlBar(song);
Expand Down Expand Up @@ -850,7 +854,7 @@
var image = $("#currentImage" + id);

if (image) {
if (song.streamUrl == currentStreamUrl) {
if (i == currentSongIndex && song.streamUrl == currentStreamUrl) {
image.show();
} else {
image.hide();
Expand All @@ -860,12 +864,7 @@
}

function getCurrentSongIndex() {
for (var i = 0; i < songs.length; i++) {
if (songs[i].streamUrl == currentStreamUrl) {
return i;
}
}
return -1;
return currentSongIndex;
}

<!-- actionSelected() is invoked when the users selects from the "More actions..." combo box. -->
Expand Down