Class SoundEngine

java.lang.Object
  extended bySoundEngine

public class SoundEngine
extends java.lang.Object

Class SoundEngine provides functionality to process sound files. Sounds can be loaded, played, paused, resumed, and stopped. The sound engine can play multiple sounds simultaniously, but only the last sound loaded can be controlled (pased, resumed, etc.). The sound engine accepts files in WAV, AIFF, and AU formats (although not all WAV files - it depends on the encoding in the file).

Version:
1.0
Author:
Michael Kolling and David J Barnes

Constructor Summary
SoundEngine()
          Create a SoundEngine that can play sound files.
 
Method Summary
 int getDuration()
          Return the duration of the currently loaded sound clip.
 void pause()
          Pause the currently playing sound.
 boolean play(java.io.File soundFile)
          Load and play a specified sound file.
 void resume()
          Resume the currently paused sound.
 void seek(int value)
          Set the current playing position in the currently playing sound to 'value'.
 void setVolume(int vol)
          Set the playback volume of the current sound.
 void stop()
          Stop the currently playing sound (if there is one playing).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SoundEngine

public SoundEngine()
Create a SoundEngine that can play sound files.

Method Detail

getDuration

public int getDuration()
Return the duration of the currently loaded sound clip.

Returns:
The duration of the current sound, or 0 if no sound has been loaded.

pause

public void pause()
Pause the currently playing sound. If no sound is currently playing, calling this method has no effect.


play

public boolean play(java.io.File soundFile)
Load and play a specified sound file. If the file is not in a recognised file format, false is returned. Otherwise the sound is started and true is returned. The method returns immediately after the sound starts (not after the sound finishes).

Parameters:
soundFile - The file to be loaded.
Returns:
True, if the sound file could be loaded, false otherwise.

resume

public void resume()
Resume the currently paused sound. If no sound is currently paused, this method has no effect.


seek

public void seek(int value)
Set the current playing position in the currently playing sound to 'value'. 'value' is a percentage value (0 to 100). If there is no sound currently playing, this method has no effect.

Parameters:
value - The target position in the sound file, as a percentage.

setVolume

public void setVolume(int vol)
Set the playback volume of the current sound. If no sound is currently loaded, this method has no effect.

Parameters:
vol - Volume level as a percentage (0..100).

stop

public void stop()
Stop the currently playing sound (if there is one playing). If no sound is playing, this method has no effect.