cage.audio
Class Sound

java.lang.Object
  extended by cage.audio.Sound

public class Sound
extends java.lang.Object

The sound class represents a sound data file and contains a player for that file. Currently the only format supported is MP3 via the JLayer library. Calling play will create a thread which reads the file and sends it to the sound card. The player in this thread is assigned to the player member field. If loop is true, when the file ends it will be opened again and played again. Calling stop will close the player and end the sound playing. If player is already assigned, that player is closed when play is called. This limits a sound to only one currently playing player at once. We did this so the script would not have to track instances of players. TODO:Removing this limit in some clean way should be a goal for future versions.

Author:
Seth Marinello

Constructor Summary
Sound(java.lang.String fileName)
          Creates a Sound which will load from the specifed filename
Sound(java.lang.String name, java.lang.String fileName, boolean loop)
          Creteas a sound with the specified resource name, fileName and looping option
 
Method Summary
 java.lang.String getFileName()
          Returns the name of the file this sound is loaded from
 boolean getLoop()
          Returns true if this sound will loop when played
 java.lang.String getName()
          Returns the resource name of the sound
 void play()
          Creates a new player and starts playback in a thread.
 void setLoop(boolean loop)
          Sets if this sound should loop or not.
 void stop()
          If a player has been created, close the player.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Sound

public Sound(java.lang.String fileName)
Creates a Sound which will load from the specifed filename

Parameters:
fileName - the file to load

Sound

public Sound(java.lang.String name,
             java.lang.String fileName,
             boolean loop)
Creteas a sound with the specified resource name, fileName and looping option

Parameters:
name - name of the sound
fileName - the file to load
loop - if the sound should loop or not
Method Detail

play

public void play()
Creates a new player and starts playback in a thread. If the Sound is set to loop, a new player will be created when the sound finishes and the sound will play again.


stop

public void stop()
If a player has been created, close the player.


getName

public java.lang.String getName()
Returns the resource name of the sound

Returns:
the sound name

getFileName

public java.lang.String getFileName()
Returns the name of the file this sound is loaded from

Returns:
the filename

getLoop

public boolean getLoop()
Returns true if this sound will loop when played

Returns:
should the sound loop

setLoop

public void setLoop(boolean loop)
Sets if this sound should loop or not.

Parameters:
loop - true if the sound should loop

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object