Im trying to build a class to provide sound support for another program. Below is the stand alone test.
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
public class AudioSupport
{
String filename;
File soundFile = null;
Clip audioClip;
AudioInputStream audio;
public AudioSupport(String string)
{
filename = string;
init();
}
public void init()
{
soundFile = new File(filename);
if (!soundFile.exists())
System.err.println("pathname does not exist: " + filename);
try {
audioClip = AudioSystem.getClip();
audio = AudioSystem.getAudioInputStream(soundFile);
audioClip.open(audio);
audioClip.start(); //a loop here doesn't seem to work either
} catch (LineUnavailableException lue)
{
System.out.println("caught: " + lue);
} catch(UnsupportedAudioFileException uafe)
{
System.out.println("caught: " + uafe);
}
catch(IOException ioe)
{
System.out.println("caught: " + ioe);
}
}
public static void main(String args[])
{
new AudioSupport("D:/path/toproject/src/Sound/notify.wav");
}
}
Can't seem to figure out whats wrong. No compile errors, but no sound either


Sign In
Create Account


Back to top









