Mp3dings 
20100427

helliker.id3
Class Playlist

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by java.util.AbstractSequentialList
              extended by java.util.LinkedList
                  extended by helliker.id3.Playlist
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, Deque, List, Queue

public class Playlist
extends LinkedList

Description: This class is treated as a winamp styled playlist. It is essentially a collection of MP3Files that can be initalised from a file. Playlists can also be written based on it's data.

See Also:
Serialized Form

Field Summary
static int MUSICMATCH_FORMAT
          The MusicMatch format
static int WINAMP_FORMAT
          The Winamp M3u Format
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Playlist()
           
 
Method Summary
 void addDirectory(File dir)
          Reads in mp3s from a directory and adds them to this playlist.
 void addDirectory(File dir, boolean recurse, boolean sort)
          Reads in mp3s from a directory and adds them to the this playlist.
 void loadFromFile(File m3uFile, int format)
          Load a playlist from a file.
 void sort()
          Sorts this playlist by using the default path comparisons.
 void sort(Comparator cmp)
          Sorts this playlist by using the specified comparator.
 String toString()
          Calls toString on every object contained within (very long).
 void writeToFile(File dest, int format)
          Writes this playlist in the format specified.
 
Methods inherited from class java.util.LinkedList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, toArray, toArray
 
Methods inherited from class java.util.AbstractSequentialList
iterator
 
Methods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList
 
Methods inherited from interface java.util.Deque
iterator
 

Field Detail

WINAMP_FORMAT

public static int WINAMP_FORMAT
The Winamp M3u Format


MUSICMATCH_FORMAT

public static int MUSICMATCH_FORMAT
The MusicMatch format

Constructor Detail

Playlist

public Playlist()
Method Detail

sort

public void sort()
Sorts this playlist by using the default path comparisons. Uses Collections.sort().


sort

public void sort(Comparator cmp)
Sorts this playlist by using the specified comparator. Uses Collections.sort().

Parameters:
cmp - the comparator to use

addDirectory

public void addDirectory(File dir)
                  throws IOException
Reads in mp3s from a directory and adds them to this playlist. By default, subdirectories will be recursed and the files will be sorted.

Parameters:
dir - the directory to look for mp3s in
Throws:
IOException - if the files specified is not a directory

addDirectory

public void addDirectory(File dir,
                         boolean recurse,
                         boolean sort)
                  throws IOException
Reads in mp3s from a directory and adds them to the this playlist. The recurse parameter should be set if you wish to grab mp3s from subdirectories as well. If the sort parameter is true the files in each directory will be sorted before added.

Parameters:
dir - the directory to look for mp3s in
recurse - whether or not to recurse subdirectories
sort - whether or not to sort each directory
Throws:
IOException - if the file specified is not a directory

loadFromFile

public void loadFromFile(File m3uFile,
                         int format)
                  throws PlaylistException,
                         IOException
Load a playlist from a file. This works with Winamp and MusicMatch playlists. The format parameter should be either WINAMP_FORMAT or MUSICMATCH_FORMAT.

Parameters:
m3uFile - the playlist file
format - the type of playlist to load
Throws:
PlaylistException - if the file is corrupt
FileNotFoundException - if an error occurs
IOException - if an error occurs

writeToFile

public void writeToFile(File dest,
                        int format)
                 throws IOException
Writes this playlist in the format specified. This can be either WINAMP_FORMAT or MUSICMATCH_FORMAT. If the destination is a directory, then the file will be created in that directory with the same name as the directory with a ".m3u" extension added. If the destination is a file then the playlist will be saved to that file. If the format argument is invalid the file will not be written.

Parameters:
dest - where to save the playlist
format - the format to write the file in
Throws:
IOException - if an error occurs

toString

public String toString()
Calls toString on every object contained within (very long).

Overrides:
toString in class AbstractCollection
Returns:
a string representation of this object

Mp3dings 
20100427