Methods Summary |
---|
public void | actionPerformed(java.awt.event.ActionEvent event)
//PLAY BUTTON
Object source = event.getSource();
if (source == playButton) {
//Try to get the AudioClip.
onceClip = soundList.getClip(chosenFile);
stopButton.setEnabled(true);
onceClip.play(); //Play it once.
status.setText("Playing sound " + chosenFile + ".");
if (onceClip == null) {
status.setText("Sound " + chosenFile + " not loaded yet.");
}
return;
}
//START LOOP BUTTON
if (source == loopButton) {
loopClip = soundList.getClip(chosenFile);
looping = true;
loopClip.loop(); //Start the sound loop.
loopButton.setEnabled(false); //Disable start button.
stopButton.setEnabled(true);
status.setText("Playing sound " + chosenFile + " continuously.");
if (loopClip == null) {
status.setText("Sound " + chosenFile + " not loaded yet.");
}
return;
}
//STOP LOOP BUTTON
if (source == stopButton) {
if (looping) {
looping = false;
loopClip.stop(); //Stop the sound loop.
loopButton.setEnabled(true); //Enable start button.
} else if (onceClip != null) {
onceClip.stop();
}
stopButton.setEnabled(false);
status.setText("Stopped playing " + chosenFile + ".");
return;
}
|
public void | itemStateChanged(java.awt.event.ItemEvent e)
chosenFile = (String)formats.getSelectedItem();
soundList.startLoading(chosenFile);
|
public static void | main(java.lang.String[] s)
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
};
JFrame f = new JFrame("SoundApplication");
f.addWindowListener(l);
f.getContentPane().add(new SoundApplication());
f.setSize(new Dimension(400,100));
f.show();
|
public void | start()
if (looping) {
loopClip.loop(); //Restart the sound loop.
}
|
void | startLoadingSounds()
//Start asynchronous sound loading.
try {
codeBase = new URL("file:" + System.getProperty("user.dir") + "/");
} catch (MalformedURLException e) {
System.err.println(e.getMessage());
}
soundList = new SoundList(codeBase);
soundList.startLoading(auFile);
soundList.startLoading(aiffFile);
soundList.startLoading(midiFile);
soundList.startLoading(rmfFile);
soundList.startLoading(wavFile);
|
public void | stop()
onceClip.stop(); //Cut short the one-time sound.
if (looping) {
loopClip.stop(); //Stop the sound loop.
}
|