comp202.fall2007.a5.util
Class SongFactory

Object
  extended by comp202.fall2007.a5.util.SongFactory

public class SongFactory
extends Object

A SongFactory enables the easy creation of Song objects representing digital audio tracks stored on disk. The created Song objects's attributes are initialized using the values stored in the metadata (ID3) tags stored in the file.


Constructor Summary
SongFactory()
          Creates a new SongFactory.
 
Method Summary
 Song createSong(String path)
           Creates a new Song object representing the MP3 audio track stored in the file given by the specified String.
static void disableLogging()
          Disable the Loggers used and created by the Jaudiotagger libraries.
static void enableLogging()
          Enable the Loggers used and created by the Jaudiotagger libraries.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SongFactory

public SongFactory()
Creates a new SongFactory.

Method Detail

createSong

public Song createSong(String path)
                throws java.io.IOException,
                       java.io.FileNotFoundException,
                       IncorrectFileExtensionException

Creates a new Song object representing the MP3 audio track stored in the file given by the specified String.

The length attribute of the new Song object is initialized from the audio header of the MP3 file, and the disc number attribute is always 1.

To initialize the artist, album, title and track number attributes of the new Song object, the method determines whether the MP3 file contains an ID3 V2 tag. If it does, then the aforementioned attributes of the new Song object are initialized using the data stored in this tag. Otherwise, the method determines whether the MP3 file contains an ID3 V1 tag; if it does, the aforementioned attributes are initialized using the data stored in this tag, otherwise, they are assigned default values.

The default value for the artist, album, and title attributes is the empty String, while the default value for the track number attribute is Song.EMPTY_TRACK. Note that if a tag is present, but one of the fields corresponding to the artist, album, title, or track number attribute is empty, the corresponding attribute in returned Song object is assigned the default value.

Parameters:
path - The path of the MP3 file which contains the audio track to be represented by the returned Song.
Returns:
A new Song objects whose attributes are initialized using values read from the file given by path.
Throws:
java.io.IOException - if there was an error reading the file specified by path.
java.io.FileNotFoundException - if the file specified by path does not exist.
IncorrectFileExtensionException - if the file specified by path does not have extension .MP3 (or case variations thereof).

enableLogging

public static void enableLogging()
Enable the Loggers used and created by the Jaudiotagger libraries. Logging is disabled by default.


disableLogging

public static void disableLogging()
Disable the Loggers used and created by the Jaudiotagger libraries. Logging is disabled by default.