Beispiel #1
0
  /**
   * Converts the response from the MPD server into a {@link org.bff.javampd.objects.MPDSong}
   * object.
   *
   * @param list the response from the MPD server
   * @return a MPDSong object
   */
  public static List<MPDSong> convertResponseToSong(List<String> list) {
    List<MPDSong> songList = new ArrayList<>();
    Iterator<String> iterator = list.iterator();

    String line = null;
    while (iterator.hasNext()) {
      if (line == null || (!line.startsWith(PREFIX_FILE))) {
        line = iterator.next();
      }

      if (line.startsWith(PREFIX_FILE)) {
        MPDSong song = new MPDSong();
        song.setFile(line.substring(PREFIX_FILE.length()).trim());
        line = iterator.next();
        while (!line.startsWith(PREFIX_FILE)) {
          processLine(song, line);
          if (!iterator.hasNext()) {
            break;
          }
          line = iterator.next();
        }
        songList.add(song);
      }
    }
    return songList;
  }
Beispiel #2
0
  public void update() {
    try {
      _mpd.getMPDAdmin().updateDatabase();
    } catch (Exception e) {
    }

    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) getRoot();
    Iterator<Path> pathIter = null;
    Path subPath = null;
    MPDSong song = null;

    try {
      Iterator<MPDSong> list = _mpd.getMPDDatabase().listAllSongs().iterator();

      parent.removeAllChildren();

      while (list.hasNext()) {
        song = list.next();
        pathIter = Paths.get(song.getFile()).iterator();
        parent = (DefaultMutableTreeNode) getRoot();

        while (pathIter.hasNext()) {
          subPath = pathIter.next();
          if (pathIter.hasNext()) {
            parent = appendNode(parent, new DefaultMutableTreeNode(subPath));
          } else {
            appendNode(parent, new DefaultMutableTreeNode(new SongContainer(song)));
          }
        }
      }
      super.reload();
    } catch (Exception e) {
    }
  }
Beispiel #3
0
 @Override
 public void processSong(MPDSong song, String line) {
   if (startsWith(line)) {
     song.setDiscNumber(line.substring(getPrefix().length()).trim());
   }
 }