use of org.libresonic.player.domain.PlayQueue in project libresonic by Libresonic.
the class PlayerDaoTestCase method testPlaylist.
@Test
public void testPlaylist() {
Player player = new Player();
playerDao.createPlayer(player);
PlayQueue playQueue = player.getPlayQueue();
assertNotNull("Missing playlist.", playQueue);
playerDao.deletePlayer(player.getId());
playerDao.createPlayer(player);
assertNotSame("Wrong playlist.", playQueue, player.getPlayQueue());
}
use of org.libresonic.player.domain.PlayQueue in project libresonic by Libresonic.
the class ShareManagementController method getMediaFiles.
private List<MediaFile> getMediaFiles(HttpServletRequest request) throws Exception {
Integer id = ServletRequestUtils.getIntParameter(request, "id");
String playerId = request.getParameter("player");
Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");
List<MediaFile> result = new ArrayList<>();
if (id != null) {
MediaFile album = mediaFileService.getMediaFile(id);
int[] indexes = ServletRequestUtils.getIntParameters(request, "i");
if (indexes.length == 0) {
return Arrays.asList(album);
}
List<MediaFile> children = mediaFileService.getChildrenOf(album, true, false, true);
for (int index : indexes) {
result.add(children.get(index));
}
} else if (playerId != null) {
Player player = playerService.getPlayerById(playerId);
PlayQueue playQueue = player.getPlayQueue();
result = playQueue.getFiles();
} else if (playlistId != null) {
result = playlistService.getFilesInPlaylist(playlistId);
}
return result;
}
use of org.libresonic.player.domain.PlayQueue in project libresonic by Libresonic.
the class RESTController method jukeboxControl.
@RequestMapping(value = "/rest/jukeboxControl", method = { RequestMethod.GET, RequestMethod.POST })
public void jukeboxControl(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request, true);
User user = securityService.getCurrentUser(request);
if (!user.isJukeboxRole()) {
error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to use jukebox.");
return;
}
boolean returnPlaylist = false;
String action = getRequiredStringParameter(request, "action");
if ("start".equals(action)) {
playQueueService.doStart(request, response);
} else if ("stop".equals(action)) {
playQueueService.doStop(request, response);
} else if ("skip".equals(action)) {
int index = getRequiredIntParameter(request, "index");
int offset = getIntParameter(request, "offset", 0);
playQueueService.doSkip(request, response, index, offset);
} else if ("add".equals(action)) {
int[] ids = getIntParameters(request, "id");
playQueueService.doAdd(request, response, ids, null);
} else if ("set".equals(action)) {
int[] ids = getIntParameters(request, "id");
playQueueService.doSet(request, response, ids);
} else if ("clear".equals(action)) {
playQueueService.doClear(request, response);
} else if ("remove".equals(action)) {
int index = getRequiredIntParameter(request, "index");
playQueueService.doRemove(request, response, index);
} else if ("shuffle".equals(action)) {
playQueueService.doShuffle(request, response);
} else if ("setGain".equals(action)) {
float gain = getRequiredFloatParameter(request, "gain");
jukeboxService.setGain(gain);
} else if ("get".equals(action)) {
returnPlaylist = true;
} else if ("status".equals(action)) {
// No action necessary.
} else {
throw new Exception("Unknown jukebox action: '" + action + "'.");
}
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
Player jukeboxPlayer = jukeboxService.getPlayer();
boolean controlsJukebox = jukeboxPlayer != null && jukeboxPlayer.getId().equals(player.getId());
PlayQueue playQueue = player.getPlayQueue();
int currentIndex = controlsJukebox && !playQueue.isEmpty() ? playQueue.getIndex() : -1;
boolean playing = controlsJukebox && !playQueue.isEmpty() && playQueue.getStatus() == PlayQueue.Status.PLAYING;
float gain = jukeboxService.getGain();
int position = controlsJukebox && !playQueue.isEmpty() ? jukeboxService.getPosition() : 0;
Response res = createResponse();
if (returnPlaylist) {
JukeboxPlaylist result = new JukeboxPlaylist();
res.setJukeboxPlaylist(result);
result.setCurrentIndex(currentIndex);
result.setPlaying(playing);
result.setGain(gain);
result.setPosition(position);
for (MediaFile mediaFile : playQueue.getFiles()) {
result.getEntry().add(createJaxbChild(player, mediaFile, username));
}
} else {
JukeboxStatus result = new JukeboxStatus();
res.setJukeboxStatus(result);
result.setCurrentIndex(currentIndex);
result.setPlaying(playing);
result.setGain(gain);
result.setPosition(position);
}
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.PlayQueue in project libresonic by Libresonic.
the class RESTController method getPlayQueue.
@RequestMapping(value = "/rest/getPlayQueue", method = { RequestMethod.GET, RequestMethod.POST })
public void getPlayQueue(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
String username = securityService.getCurrentUsername(request);
Player player = playerService.getPlayer(request, response);
SavedPlayQueue playQueue = playQueueDao.getPlayQueue(username);
if (playQueue == null) {
writeEmptyResponse(request, response);
return;
}
org.libresonic.restapi.PlayQueue restPlayQueue = new org.libresonic.restapi.PlayQueue();
restPlayQueue.setUsername(playQueue.getUsername());
restPlayQueue.setCurrent(playQueue.getCurrentMediaFileId());
restPlayQueue.setPosition(playQueue.getPositionMillis());
restPlayQueue.setChanged(jaxbWriter.convertDate(playQueue.getChanged()));
restPlayQueue.setChangedBy(playQueue.getChangedBy());
for (Integer mediaFileId : playQueue.getMediaFileIds()) {
MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
if (mediaFile != null) {
restPlayQueue.getEntry().add(createJaxbChild(player, mediaFile, username));
}
}
Response res = createResponse();
res.setPlayQueue(restPlayQueue);
jaxbWriter.writeResponse(request, response, res);
}
Aggregations