/** * Retrieves a string representation of the object. * * @return a string representation of the object. * @see java.lang.Object#toString() */ public String toString() { StringBuffer sb = new StringBuffer(); for (Music m : list.getMusic()) { sb.append(m.toString() + "\n"); } return sb.toString(); }
/** * Removes entries from playlist. * * @param songIds entries IDs. * @throws MPDServerException if an error occur while contacting server. */ public void removeById(int[] songIds) throws MPDServerException { for (int id : songIds) this.mpd.getMpdConnection().queueCommand(MPD_CMD_PLAYLIST_REMOVE_ID, Integer.toString(id)); this.mpd.getMpdConnection().sendCommandQueue(); for (int id : songIds) list.removeById(id); }
/** * Reload playlist content. <code>refresh</code> has better performance and is more server * friendly, use it whenever possible. * * @see #refresh(int) * @throws MPDServerException if an error occur while contacting server. * @return current playlist version. */ private int refresh() throws MPDServerException { if (firstRefreash) { // TODO should be atomic MPDStatus status = this.mpd.getStatus(); List<String> response = this.mpd.getMpdConnection().sendCommand(MPD_CMD_PLAYLIST_LIST); List<Music> playlist = Music.getMusicFromList(response, false); list.clear(); list.addAll(playlist); lastPlaylistVersion = status.getPlaylistVersion(); firstRefreash = false; } else { this.lastPlaylistVersion = this.refresh(lastPlaylistVersion); } return this.lastPlaylistVersion; }
/** * Removes entries from playlist. * * @param songs entries positions. * @throws MPDServerException if an error occur while contacting server. * @see #removeById(int[]) */ public void removeByIndex(int[] songs) throws MPDServerException { java.util.Arrays.sort(songs); for (int i = songs.length - 1; i >= 0; i--) this.mpd.getMpdConnection().queueCommand(MPD_CMD_PLAYLIST_REMOVE, Integer.toString(songs[i])); this.mpd.getMpdConnection().sendCommandQueue(); for (int i = songs.length - 1; i >= 0; i--) list.removeByIndex(songs[i]); }
/** * Clears playlist content. * * @throws MPDServerException if an error occur while contacting server. */ public void clear() throws MPDServerException { this.mpd.getMpdConnection().sendCommand(MPD_CMD_PLAYLIST_CLEAR); list.clear(); }
/** * Retrieves playlist size. Operates on local copy of playlist, may not reflect server's current * playlist. You may call refresh() before calling size(). * * @return playlist size. */ public int size() { return list.size(); }
/** * Remove playlist entry with ID songId * * @param songId id of the entry to be removed. * @throws MPDServerException if an error occur while contacting server. */ public void removeById(int songId) throws MPDServerException { this.mpd.getMpdConnection().sendCommand(MPD_CMD_PLAYLIST_REMOVE_ID, Integer.toString(songId)); list.removeById(songId); }
/** * Remove playlist entry at position index. * * @param position position of the entry to be removed. * @throws MPDServerException if an error occur while contacting server. * @see #removeId(int) */ public void removeByIndex(int position) throws MPDServerException { this.mpd.getMpdConnection().sendCommand(MPD_CMD_PLAYLIST_REMOVE, Integer.toString(position)); list.removeByIndex(position); }
/** * Retrieves music at position index in playlist. Operates on local copy of playlist, may not * reflect server's current playlist. * * @param index position. * @return music at position index. */ public Music getByIndex(int index) { return list.getByIndex(index); }