use of org.libresonic.player.domain.Player in project libresonic by Libresonic.
the class HLSController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Access-Control-Allow-Origin", "*");
int id = ServletRequestUtils.getIntParameter(request, "id");
MediaFile mediaFile = mediaFileService.getMediaFile(id);
Player player = playerService.getPlayer(request, response);
String username = player.getUsername();
if (mediaFile == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Media file not found: " + id);
return null;
}
if (username != null && !securityService.isFolderAccessAllowed(mediaFile, username)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access to file " + mediaFile.getId() + " is forbidden for user " + username);
return null;
}
Integer duration = mediaFile.getDurationSeconds();
if (duration == null || duration == 0) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unknown duration for media file: " + id);
return null;
}
response.setContentType("application/vnd.apple.mpegurl");
response.setCharacterEncoding(StringUtil.ENCODING_UTF8);
List<Pair<Integer, Dimension>> bitRates = parseBitRates(request);
PrintWriter writer = response.getWriter();
if (bitRates.size() > 1) {
generateVariantPlaylist(request, id, player, bitRates, writer);
} else {
generateNormalPlaylist(request, id, player, bitRates.size() == 1 ? bitRates.get(0) : null, duration, writer);
}
return null;
}
use of org.libresonic.player.domain.Player in project libresonic by Libresonic.
the class StatusServiceTestCase method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
service = new StatusService();
player1 = new Player();
player1.setId("1");
}
use of org.libresonic.player.domain.Player in project libresonic by Libresonic.
the class TranscodingDaoTestCase method testPlayerTranscoding.
@Test
public void testPlayerTranscoding() {
Player player = new Player();
playerDao.createPlayer(player);
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
Transcoding transcodingA = transcodingDao.getAllTranscodings().get(0);
Transcoding transcodingB = transcodingDao.getAllTranscodings().get(1);
Transcoding transcodingC = transcodingDao.getAllTranscodings().get(2);
List<Transcoding> activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[] { transcodingA.getId() });
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 1, activeTranscodings.size());
assertTranscodingEquals(transcodingA, activeTranscodings.get(0));
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[] { transcodingB.getId(), transcodingC.getId() });
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 2, activeTranscodings.size());
assertTranscodingEquals(transcodingB, activeTranscodings.get(0));
assertTranscodingEquals(transcodingC, activeTranscodings.get(1));
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[0]);
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
}
use of org.libresonic.player.domain.Player in project libresonic by Libresonic.
the class PlayerDaoTestCase method testDefaultValues.
@Test
public void testDefaultValues() {
playerDao.createPlayer(new Player());
Player player = playerDao.getAllPlayers().get(0);
assertTrue("Player should have dynamic IP by default.", player.isDynamicIp());
assertTrue("Player should be auto-controlled by default.", player.isAutoControlEnabled());
assertNull("Player client ID should be null by default.", player.getClientId());
}
use of org.libresonic.player.domain.Player in project libresonic by Libresonic.
the class PlayerDaoTestCase method testUpdatePlayer.
@Test
public void testUpdatePlayer() {
Player player = new Player();
playerDao.createPlayer(player);
assertPlayerEquals(player, playerDao.getAllPlayers().get(0));
player.setName("name");
player.setType("Winamp");
player.setTechnology(PlayerTechnology.WEB);
player.setClientId("foo");
player.setUsername("username");
player.setIpAddress("ipaddress");
player.setDynamicIp(true);
player.setAutoControlEnabled(false);
player.setLastSeen(new Date());
player.setTranscodeScheme(TranscodeScheme.MAX_160);
playerDao.updatePlayer(player);
Player newPlayer = playerDao.getAllPlayers().get(0);
assertPlayerEquals(player, newPlayer);
}
Aggregations