com.limegroup.gnutella.gui.mp3
Class PlayList

java.lang.Object
  extended bycom.limegroup.gnutella.gui.mp3.PlayList

public class PlayList
extends java.lang.Object

This class encapsulates the abstraction of a mp3 playlist (.m3u). This class IS thread-safe.


Constructor Summary
PlayList(java.lang.String filename)
          Creates a PlayList accessible from the given filename.
 
Method Summary
 int addSong(java.io.File newEntry)
          Adds a song to the playlist.
 int addSong(java.lang.String filename)
          Adds a song to the playlist.
 void deleteSong(int index)
          Deletes a song from the playlist.
 int getCurrSongIndex()
          Get the index of the currently 'playing' file.
 int getIndexOfSong(java.io.File in)
          Get the current index of the referenced song File; returns -1 if that song is not in this Playlist.
 java.io.File getNextSong()
          For your convenience, this method can be called repeatedly to get the next song to play.
 int getNumSongs()
          Get the total number of songs in current playlist, including those that were recently added.
 java.io.File getSong(int index)
          Get a reference to the File at the indicated index in the playlist.
 boolean isShuffled()
          Returns whether the songs should be 'shuffled'.
static void main(java.lang.String[] argv)
           
 void save()
          Call this when you want to save the contents of the playlist.
 void setBackwardsMode()
          If you want the next call to getNextSong() to return the previous song that was 'played', call this method.
 int setCurrSongIndex(int index)
          Set the index of the currently 'playing' file.
 void sortByName()
          Sort the playlist by name, toggling between ascending and descending orders.
 void toggleShuffle()
          Toggles 'shuffled' mode for playing songs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlayList

public PlayList(java.lang.String filename)
         throws java.lang.Exception
Creates a PlayList accessible from the given filename. If the File 'filename' exists, the playlist is loaded from that file.

Throws:
java.lang.Exception - Thrown if input filename is an invalid m3u file.
Method Detail

getCurrSongIndex

public int getCurrSongIndex()
Get the index of the currently 'playing' file.


setCurrSongIndex

public int setCurrSongIndex(int index)
Set the index of the currently 'playing' file.


setBackwardsMode

public void setBackwardsMode()
If you want the next call to getNextSong() to return the previous song that was 'played', call this method. This only lasts one call to getNextSong(). Moreover, the 'history' for shuffled mode is only 1 song.


isShuffled

public boolean isShuffled()
Returns whether the songs should be 'shuffled'.


toggleShuffle

public void toggleShuffle()
Toggles 'shuffled' mode for playing songs.


save

public void save()
          throws java.lang.Exception
Call this when you want to save the contents of the playlist.

Throws:
java.lang.Exception - Throw when save failed.

getNumSongs

public int getNumSongs()
Get the total number of songs in current playlist, including those that were recently added.


addSong

public int addSong(java.lang.String filename)
Adds a song to the playlist.

Returns:
the index of the song added. -1 is returned if the song was not successfuly added.

deleteSong

public void deleteSong(int index)
Deletes a song from the playlist. The list is capsized, meaning all indices following the deleted should be decremented by one. This is the natural JTable deletion semantics.


addSong

public int addSong(java.io.File newEntry)
Adds a song to the playlist.

Returns:
the index of the song added; -1 is returned if the song was not successfuly added

getNextSong

public java.io.File getNextSong()
For your convenience, this method can be called repeatedly to get the next song to play. Assumes the repeat button is pressed. If a user picks a certain song, use getSong(int).


getSong

public java.io.File getSong(int index)
Get a reference to the File at the indicated index in the playlist.


getIndexOfSong

public int getIndexOfSong(java.io.File in)
Get the current index of the referenced song File; returns -1 if that song is not in this Playlist.


sortByName

public void sortByName()
Sort the playlist by name, toggling between ascending and descending orders.


main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Throws:
java.lang.Exception