Search in sources :

Example 16 with Player

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;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Player(org.libresonic.player.domain.Player) Pair(org.libresonic.player.util.Pair) PrintWriter(java.io.PrintWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Player

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");
}
Also used : Player(org.libresonic.player.domain.Player)

Example 18 with Player

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());
}
Also used : Player(org.libresonic.player.domain.Player) Transcoding(org.libresonic.player.domain.Transcoding) Test(org.junit.Test)

Example 19 with Player

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());
}
Also used : Player(org.libresonic.player.domain.Player) Test(org.junit.Test)

Example 20 with Player

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);
}
Also used : Player(org.libresonic.player.domain.Player) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Player (org.libresonic.player.domain.Player)25 Test (org.junit.Test)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 MediaFile (org.libresonic.player.domain.MediaFile)4 User (org.libresonic.player.domain.User)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Transcoding (org.libresonic.player.domain.Transcoding)3 File (java.io.File)2 PlayQueue (org.libresonic.player.domain.PlayQueue)2 Playlist (org.libresonic.player.domain.Playlist)2 TransferStatus (org.libresonic.player.domain.TransferStatus)2 UserSettings (org.libresonic.player.domain.UserSettings)2 RedirectView (org.springframework.web.servlet.view.RedirectView)2 PrintWriter (java.io.PrintWriter)1 DateFormat (java.text.DateFormat)1 Cookie (javax.servlet.http.Cookie)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1