com.isti.util
Class IstiSound

java.lang.Object
  extended by com.isti.util.IstiSound
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, javax.sound.sampled.LineListener

public class IstiSound
extends java.lang.Object
implements javax.sound.sampled.LineListener, java.awt.event.ActionListener

Class IstiSound is a sound utility class that manages a sound 'Clip' object. The ActionListener interface is implemented to support the use of a javax.swing.Timer to play the sound.


Field Summary
protected  javax.sound.sampled.Clip clipObj
           
protected  long stopPlayTimeVal
           
 
Constructor Summary
IstiSound(javax.sound.sampled.AudioInputStream audiosource)
          Creates a sound from the specified audio input stream.
IstiSound(java.io.File file)
          Creates a sound from the specified sound file.
IstiSound(java.io.InputStream stmObj)
          Creates a sound from the specified input stream.
IstiSound(java.net.URL url)
          Creates a sound from the specified sound file.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Supports the ActionListener interface.
 void close()
          Release resources associated with this sound object.
 boolean isActive()
          Checks if a sound is active
 boolean isOpen()
          Queries whether or not this sound object is open.
static boolean isSoundFile(java.io.File file)
          Checks if the specified file is a supported sound file.
static boolean isSoundFile(java.net.URL url)
          Checks if the specified file is a supported sound file.
 void loop()
          Plays a sound continuously.
 void loop(int count)
          Plays a sound the specified number of times.
 void play()
          Plays a sound from start to finish.
 void play(boolean waitFlag)
          Plays a sound from start to finish.
 void play(int secondsVal)
          Plays a sound for the specified duration.
 void reopen(javax.sound.sampled.AudioInputStream audiosource)
          Reopens to use the sound from the specified audio input stream.
 void reopen(java.io.File file)
          Reopens to use the sound from the specified sound file.
 void reopen(java.io.InputStream stmObj)
          Reopens to use the sound from the specified input stream.
 void reopen(java.net.URL url)
          Reopens to use the sound from the specified sound file.
 void reset()
          Resets a sound to the beginning.
 void start()
          Starts or resumes playing a sound from the current position.
 void stop()
          Stops playing a sound.
 void update(javax.sound.sampled.LineEvent lineEvent)
          Supports the LineListener interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clipObj

protected final javax.sound.sampled.Clip clipObj

stopPlayTimeVal

protected long stopPlayTimeVal
Constructor Detail

IstiSound

public IstiSound(javax.sound.sampled.AudioInputStream audiosource)
          throws java.io.IOException,
                 javax.sound.sampled.LineUnavailableException
Creates a sound from the specified audio input stream.

Parameters:
audiosource - audio input stream
Throws:
java.io.IOException - if an I/O exception occurs
javax.sound.sampled.LineUnavailableException - if a matching line is not available due to resource restrictions

IstiSound

public IstiSound(java.io.File file)
          throws javax.sound.sampled.UnsupportedAudioFileException,
                 java.io.IOException,
                 javax.sound.sampled.LineUnavailableException
Creates a sound from the specified sound file.

Parameters:
file - the sound file
Throws:
javax.sound.sampled.UnsupportedAudioFileException - if the File does not point to a valid sound file data recognized by the system
java.io.IOException - if an I/O exception occurs
javax.sound.sampled.LineUnavailableException - if a matching line is not available due to resource restrictions
See Also:
play

IstiSound

public IstiSound(java.net.URL url)
          throws javax.sound.sampled.UnsupportedAudioFileException,
                 java.io.IOException,
                 javax.sound.sampled.LineUnavailableException
Creates a sound from the specified sound file.

Parameters:
url - URL for the sound file
Throws:
javax.sound.sampled.UnsupportedAudioFileException - if the File does not point to a valid sound file data recognized by the system
java.io.IOException - if an I/O exception occurs
javax.sound.sampled.LineUnavailableException - if a matching line is not available due to resource restrictions
See Also:
play

IstiSound

public IstiSound(java.io.InputStream stmObj)
          throws javax.sound.sampled.UnsupportedAudioFileException,
                 java.io.IOException,
                 javax.sound.sampled.LineUnavailableException
Creates a sound from the specified input stream.

Parameters:
stmObj - the input stream to use.
Throws:
javax.sound.sampled.UnsupportedAudioFileException - if the File does not point to a valid sound file data recognized by the system
java.io.IOException - if an I/O exception occurs
javax.sound.sampled.LineUnavailableException - if a matching line is not available due to resource restrictions
See Also:
play
Method Detail

reopen

public void reopen(javax.sound.sampled.AudioInputStream audiosource)
            throws java.io.IOException,
                   javax.sound.sampled.LineUnavailableException
Reopens to use the sound from the specified audio input stream. The format of new sound must be the same as the previous sound.

Parameters:
audiosource - audio input stream
Throws:
java.io.IOException - if an I/O exception occurs
javax.sound.sampled.LineUnavailableException - if a matching line is not available due to resource restrictions

reopen

public void reopen(java.io.File file)
            throws javax.sound.sampled.UnsupportedAudioFileException,
                   java.io.IOException,
                   javax.sound.sampled.LineUnavailableException
Reopens to use the sound from the specified sound file. The format of new sound must be the same as the previous sound.

Parameters:
file - the sound file
Throws:
javax.sound.sampled.UnsupportedAudioFileException - if the File does not point to a valid sound file data recognized by the system
java.io.IOException - if an I/O exception occurs
javax.sound.sampled.LineUnavailableException - if a matching line is not available due to resource restrictions
See Also:
play

reopen

public void reopen(java.net.URL url)
            throws javax.sound.sampled.UnsupportedAudioFileException,
                   java.io.IOException,
                   javax.sound.sampled.LineUnavailableException
Reopens to use the sound from the specified sound file. The format of new sound must be the same as the previous sound.

Parameters:
url - URL for the sound file
Throws:
javax.sound.sampled.UnsupportedAudioFileException - if the File does not point to a valid sound file data recognized by the system
java.io.IOException - if an I/O exception occurs
javax.sound.sampled.LineUnavailableException - if a matching line is not available due to resource restrictions
See Also:
play

reopen

public void reopen(java.io.InputStream stmObj)
            throws javax.sound.sampled.UnsupportedAudioFileException,
                   java.io.IOException,
                   javax.sound.sampled.LineUnavailableException
Reopens to use the sound from the specified input stream. The format of new sound must be the same as the previous sound.

Parameters:
stmObj - the input stream to use.
Throws:
javax.sound.sampled.UnsupportedAudioFileException - if the File does not point to a valid sound file data recognized by the system
java.io.IOException - if an I/O exception occurs
javax.sound.sampled.LineUnavailableException - if a matching line is not available due to resource restrictions
See Also:
play

isSoundFile

public static boolean isSoundFile(java.io.File file)
Checks if the specified file is a supported sound file.

Parameters:
file - the sound file
Returns:
true if the file is supported

isSoundFile

public static boolean isSoundFile(java.net.URL url)
Checks if the specified file is a supported sound file.

Parameters:
url - URL for the sound file
Returns:
true if the file is supported

isActive

public boolean isActive()
Checks if a sound is active

Returns:
true if a sound is active

loop

public void loop()
Plays a sound continuously.


loop

public void loop(int count)
Plays a sound the specified number of times.

Parameters:
count - number of times to play the sound

play

public void play(boolean waitFlag)
Plays a sound from start to finish. This is the same as calling reset and then start.

Parameters:
waitFlag - if true then this method blocks until the playing of the sound is complete.
See Also:
reset, start

play

public void play()
Plays a sound from start to finish. This is the same as calling reset and then start.

See Also:
reset, start

play

public void play(int secondsVal)
Plays a sound for the specified duration.

Parameters:
secondsVal - play duration in seconds.

update

public void update(javax.sound.sampled.LineEvent lineEvent)
Supports the LineListener interface. Invoked when a line's status changes.

Specified by:
update in interface javax.sound.sampled.LineListener
Parameters:
lineEvent - line event

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Supports the ActionListener interface. Invoked when an action occurs.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - action event.

reset

public void reset()
Resets a sound to the beginning.


start

public void start()
Starts or resumes playing a sound from the current position.


stop

public void stop()
Stops playing a sound.


close

public void close()
Release resources associated with this sound object. The sound cannot be played after this method is called.


isOpen

public boolean isOpen()
Queries whether or not this sound object is open.

Returns:
true if open, false if not.