The Clips Loader
ClipsLoader stores a collection of ClipInfo objects in a HashMap, keyed by their names. The name and filename for a clip are obtained from a sounds information file, which is loaded when ClipsLoader is created. The information file is assumed to be in the subdirectory Sounds/.
ClipsLoader allows a specified clip to be played, paused, resumed, looped, and stopped. A SoundsWatcher can be attached to a clip. All this functionality is handled in the ClipInfo object for the clip.
Tip
It's possible for many clips to play simultaneously, since each ClipInfo object is responsible for playing its own clip.
The first ClipsLoader constructor loads a sounds information file, and the second initializes the HashMap of clips:
// globals
private HashMap clipsMap;
/* The key is the clip 'name', the object (value)
is a ClipInfo object /
public ClipsLoader(String soundsFnm)
{ this();
loadSoundsFile(soundsFnm);
}
public ClipsLoader()
{ clipsMap = new HashMap(); }
loadSoundsFile() parses the information file, assuming each line contains a name and filename. For example, clipsInfo.txt used by LoadersTests is:
// sounds
cat cat.wav
chicken chicken.wav
dog dog.wav
sheep sheep.wavTip
The name can be any string. The file may contain blank lines and comment lines beginning with //.
After a line's name and filename have been extracted, load() is called:
public void load(String name, String fnm) // create a ClipInfo object for name and store it { if (clipsMap.containsKey(name)) System.out.println( ...