Search in sources :

Example 6 with Player

use of org.libresonic.player.domain.Player in project libresonic by Libresonic.

the class M3UController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    response.setContentType("audio/x-mpegurl");
    response.setCharacterEncoding(StringUtil.ENCODING_UTF8);
    Player player = playerService.getPlayer(request, response);
    String url = NetworkService.getBaseUrl(request);
    url = url + "ext/stream?";
    if (player.isExternalWithPlaylist()) {
        createClientSidePlaylist(response.getWriter(), player, url);
    } else {
        createServerSidePlaylist(response.getWriter(), player, url);
    }
    return null;
}
Also used : Player(org.libresonic.player.domain.Player) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Player

use of org.libresonic.player.domain.Player in project libresonic by Libresonic.

the class MoreController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();
    User user = securityService.getCurrentUser(request);
    String uploadDirectory = null;
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    if (musicFolders.size() > 0) {
        uploadDirectory = new File(musicFolders.get(0).getPath(), "Incoming").getPath();
    }
    StringBuilder jamstashUrl = new StringBuilder("http://jamstash.com/#/settings?u=" + StringUtil.urlEncode(user.getUsername()) + "&url=");
    jamstashUrl.append(StringUtil.urlEncode(NetworkService.getBaseUrl(request)));
    Player player = playerService.getPlayer(request, response);
    ModelAndView result = new ModelAndView();
    result.addObject("model", map);
    map.put("user", user);
    map.put("uploadDirectory", uploadDirectory);
    map.put("genres", mediaFileService.getGenres(false));
    map.put("currentYear", Calendar.getInstance().get(Calendar.YEAR));
    map.put("musicFolders", musicFolders);
    map.put("clientSidePlaylist", player.isExternalWithPlaylist() || player.isWeb());
    map.put("brand", settingsService.getBrand());
    map.put("jamstashUrl", jamstashUrl);
    return result;
}
Also used : Player(org.libresonic.player.domain.Player) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) MusicFolder(org.libresonic.player.domain.MusicFolder) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with Player

use of org.libresonic.player.domain.Player in project libresonic by Libresonic.

the class PlaylistController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    Player player = playerService.getPlayer(request, response);
    Playlist playlist = playlistService.getPlaylist(id);
    if (playlist == null) {
        return new ModelAndView(new RedirectView("notFound"));
    }
    map.put("playlist", playlist);
    map.put("user", user);
    map.put("player", player);
    map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username));
    map.put("partyMode", userSettings.isPartyModeEnabled());
    return new ModelAndView("playlist", "model", map);
}
Also used : Player(org.libresonic.player.domain.Player) Playlist(org.libresonic.player.domain.Playlist) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) UserSettings(org.libresonic.player.domain.UserSettings) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Player

use of org.libresonic.player.domain.Player in project libresonic by Libresonic.

the class StatusService method getPlayStatuses.

public synchronized List<PlayStatus> getPlayStatuses() {
    Map<String, PlayStatus> result = new LinkedHashMap<String, PlayStatus>();
    for (PlayStatus remotePlay : remotePlays) {
        if (!remotePlay.isExpired()) {
            result.put(remotePlay.getPlayer().getId(), remotePlay);
        }
    }
    List<TransferStatus> statuses = new ArrayList<TransferStatus>();
    statuses.addAll(inactiveStreamStatuses.values());
    statuses.addAll(streamStatuses);
    for (TransferStatus streamStatus : statuses) {
        Player player = streamStatus.getPlayer();
        File file = streamStatus.getFile();
        if (file == null) {
            continue;
        }
        MediaFile mediaFile = mediaFileService.getMediaFile(file);
        if (player == null || mediaFile == null) {
            continue;
        }
        Date time = new Date(System.currentTimeMillis() - streamStatus.getMillisSinceLastUpdate());
        result.put(player.getId(), new PlayStatus(mediaFile, player, time));
    }
    return new ArrayList<PlayStatus>(result.values());
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Player(org.libresonic.player.domain.Player) TransferStatus(org.libresonic.player.domain.TransferStatus) MediaFile(org.libresonic.player.domain.MediaFile) File(java.io.File) PlayStatus(org.libresonic.player.domain.PlayStatus)

Example 10 with Player

use of org.libresonic.player.domain.Player in project libresonic by Libresonic.

the class PlaylistService method createPlaylistForPlayQueue.

public int createPlaylistForPlayQueue() {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    HttpServletResponse response = WebContextFactory.get().getHttpServletResponse();
    Player player = playerService.getPlayer(request, response);
    Locale locale = localeResolver.resolveLocale(request);
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale);
    Date now = new Date();
    Playlist playlist = new Playlist();
    playlist.setUsername(securityService.getCurrentUsername(request));
    playlist.setCreated(now);
    playlist.setChanged(now);
    playlist.setShared(false);
    playlist.setName(dateFormat.format(now));
    playlistService.createPlaylist(playlist);
    playlistService.setFilesInPlaylist(playlist.getId(), player.getPlayQueue().getFiles());
    return playlist.getId();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Player(org.libresonic.player.domain.Player) Playlist(org.libresonic.player.domain.Playlist) DateFormat(java.text.DateFormat) HttpServletResponse(javax.servlet.http.HttpServletResponse)

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