public void remove(Track track) { synchronized (this) { docElt.removeChild(track.getElement()); tracks.remove(track); hash.remove(track.getKey()); } }
public Track add(Track track) { synchronized (this) { Track copy; if ((copy = getTrack(track)) == null) { copy = new Track((Element) doc.importNode(track.getElement(), false)); docElt.appendChild(copy.getElement()); tracks.add(copy); hash.put(copy.getKey(), copy); } return copy; } }
public void load(InputStream is) throws IOException, ParserConfigurationException, SAXException { doc = db.parse(is); docElt = doc.getDocumentElement(); if (docElt.getTagName().equals(docElementName)) { NodeList nl = docElt.getElementsByTagName(trackElementName); for (int i = 0; i < nl.getLength(); i++) { Element elt = (Element) nl.item(i); Track track = new Track(elt); tracks.add(track); hash.put(track.getKey(), track); } } }
private void playTrack() { try { synchronized (this) { speaking = playListManager.getTrackDatabase().isRoboJockEnabled(); // If a next track has been chosen by the user, use that, otherwise // pick one intelligently. currentTrack = nextTrack != null ? nextTrack : playListManager.chooseTrack(); toKeepPlaying = true; nextTrack = null; } if (currentTrack != null) { notifyUpdateListeners(); File file = currentTrack.getFile(); if (file.exists()) { if (speaking) { try { speech.say( (currentTrack.isRated() ? "" : "Unrated. ") + currentTrack.getTitle() + " by " + currentTrack.getArtist()); } catch (Exception e) { e.printStackTrace(); } finally { speaking = false; } } if (toKeepPlaying) { playFile(file); if (toKeepPlaying) { currentTrack.incNoOfTimesPlayed(); playListManager.getTrackDatabase().incNoOfPlays(); } } } else speaking = false; } } catch (Exception e) { e.printStackTrace(); } finally { try { sleep(500); } catch (InterruptedException e) { } } }
public void setRating(int rating) { currentTrack.setRating(rating); }
public void purge() { for (int i = tracks.size() - 1; i >= 0; i--) { Track track = (Track) tracks.elementAt(i); if (track.isHidden()) tracks.remove(i); } }
private int compare(Track track0, Track track1) { return track0.getName().compareTo(track1.getName()); }
public float getProbability(Track track) { if (track.getFile() == null) return 0; return track.getProbability(); }
public Track getTrack(Track track) { return getTrack(track.getKey()); }
public boolean equals(Track track) { return getURL().equals(track.getURL()); }