package lawyer; import java.applet.*; import java.net.*; /** *
This class loads in and plays sound files. Because of the way sound is
* done in Java 1.1, this class can only be used in conjunction with an Applet.
*
* @author David Danks
* @author Joel Smith
* @version 1.0; July 24, 1998
* @see LessonManager
*/
public class SoundPlayer {
Applet app;
URL[] sounds;
AudioClip[] clip;
int current = 0;
/**
* This constructor loads in the files (relative to the parent Applet's
* codeBase).
*
* @param files A one-dimensional String array of the names of the sound
* files to be loaded.
* @param parent The Applet with which the SoundPlayer is associated.
*/
public SoundPlayer(String[] files, Applet parent) {
sounds = new URL[files.length];
for (int i=0; ipointer
index, and sets the current
* index to that value.
*
* @param pointer The index of the sound to stop and make current.
*/
public void stopSound(int pointer) {
pointer = (pointer < 0) ? 0 : pointer;
pointer = (pointer > clip.length-1) ? clip.length-1 : pointer;
current = pointer;
clip[pointer].stop();
}
/**
* Stops the current sound
*/
public void stopSound() { stopSound(current); }
/**
* Sets the current sound to curr
*
* @param curr The index of the sound to be current
*/
public void setCurrentSound(int curr) {
curr = (curr < 0) ? 0 : curr;
current = (curr > clip.length-1) ? clip.length-1 : curr;
}
/**
* @return The number of sounds contained in the SoundPlayer
*/
public int getNumSounds() { return clip.length; }
/**
* Load all of the sounds in the SoundPlayer. This is currently already
* called by the contructors, so you don't need to explicitly call this.
*/
public void loadSounds(){
clip = new AudioClip[sounds.length];
for(int i = 0; i < sounds.length; i++){
clip[i] = app.getAudioClip(sounds[i]); }
}
}