private List<MediaFile> search(String query) throws IOException { SearchCriteria criteria = new SearchCriteria(); criteria.setQuery(query); criteria.setOffset(0); criteria.setCount(50); SearchResult result = searchService.search(criteria, SearchService.IndexType.SONG); return result.getMediaFiles(); }
public ModelAndView playlist(HttpServletRequest request, HttpServletResponse response) throws Exception { // Create array of players to control. If the "player" attribute is set for this session, // only the player with this ID is controlled. Otherwise, all players are controlled. List<Player> players = playerService.getAllPlayers(); String playerId = (String) request.getSession().getAttribute("player"); if (playerId != null) { Player player = playerService.getPlayerById(playerId); if (player != null) { players = Arrays.asList(player); } } Map<String, Object> map = new HashMap<String, Object>(); for (Player player : players) { Playlist playlist = player.getPlaylist(); map.put("playlist", playlist); if (request.getParameter("play") != null) { MediaFile file = mediaFileService.getMediaFile(request.getParameter("play")); playlist.addFiles(false, file); } else if (request.getParameter("add") != null) { MediaFile file = mediaFileService.getMediaFile(request.getParameter("add")); playlist.addFiles(true, file); } else if (request.getParameter("skip") != null) { playlist.setIndex(Integer.parseInt(request.getParameter("skip"))); } else if (request.getParameter("clear") != null) { playlist.clear(); } else if (request.getParameter("load") != null) { playlistService.loadPlaylist(playlist, request.getParameter("load")); } else if (request.getParameter("random") != null) { List<MediaFile> randomFiles = searchService.getRandomSongs(new RandomSearchCriteria(20, null, null, null, null)); playlist.addFiles(false, randomFiles); } } map.put("players", players); return new ModelAndView("wap/playlist", "model", map); }