To implement sound I have been using a SoundEffect class which plays .wav files, I thought I diagnosed my problem as using that file type, and tried using .snd instead, but it didn't work. An example I found on the Sun website used
play(getClass().getResource("audio/xyz.au"));
but that only seems to work if the class extends Applet and I am extending Canvas.Here is some of the code I'm currently using in the SoundEffect class.
SoundEffect(String soundFileName) {
try {
// Use URL (instead of File) to read from disk and JAR.
URL url = this.getClass().getClassLoader().getResource(soundFileName);
// Set up an audio input stream piped from the sound file.
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
// Get a clip resource.
clip = AudioSystem.getClip();
// Open audio clip and load samples from the audio input stream.
clip.open(audioInputStream);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
// Play or Re-play the sound effect from the beginning, by rewinding.
public void play() {
if (volume != Volume.MUTE) {
volume = Volume.HIGH;
if (clip.isRunning())
clip.stop(); // Stop the player if it is still running
clip.setFramePosition(0); // rewind to the beginning
clip.loop(0); // Start playing
clip.start();
}
}
Any/all help would be appreciated.

New Topic/Question
Reply




MultiQuote








|