T
Turner
Hello, Java gurus,
I'm currently writing an applet that uses the Java Sound API. I'm
encountering a strange problem in obtaining a SourceDataLine. I try
setting up two lines for two different WAV files (unencoded PCM,
nothing fancy) over the internet (although they're currently on
localhost). The first gets a line just fine. When I try to create a
second one, though, it hangs indefinitely. So I added debugging
printlns, and it appears to be getting stuck at the call to
AudioSystem.getAudioFileFormat(URL u)--the statement "Getting audio
format" is never printed. I can't for the life of me figure out what's
going on. As you can see below, I'm catching generic exceptions, so it
can't be an exception that somehow slipped by.
It can't be something wrong with the second file, because I got the
same problem when I tried to get the lines in the opposite order. Does
anyone see anything suspect in the code below/know what could be
causing this problem?
=================CODE=========================
public SourceDataLine line;
public URL url;
public AudioInputStream stream;
public StreamingSound(String url) throws
MalformedURLException,
UnsupportedAudioFileException
{
this.url = new URL(url);
try {
stream = AudioSystem.getAudioInputStream(this.url);
debug("Got an input stream");
}
catch(IOException e) {
e.printStackTrace();
}
debug("About to try getting the line");
try {
debug("Getting file format at URL: " + this.url);
AudioFileFormat fileFormat =
AudioSystem.getAudioFileFormat(this.url);
debug("Getting audio format");
AudioFormat format = fileFormat.getFormat();
debug("Getting DataLine.Info");
DataLine.Info info = new
DataLine.Info(SourceDataLine.class, format);
if (!AudioSystem.isLineSupported(info)) {
System.err.println("Line " + format + " not
supported");
}
try {
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format);
debug("Opened the line");
} catch (LineUnavailableException e) {
System.err.println("Line not available.");
e.printStackTrace();
System.exit(0);
}
}
catch(IOException e) {
e.printStackTrace();
}
catch(Exception e) {
System.err.println("Exception encountered: " +
e.getMessage());
e.printStackTrace();
}
}
===========================================
I'm currently writing an applet that uses the Java Sound API. I'm
encountering a strange problem in obtaining a SourceDataLine. I try
setting up two lines for two different WAV files (unencoded PCM,
nothing fancy) over the internet (although they're currently on
localhost). The first gets a line just fine. When I try to create a
second one, though, it hangs indefinitely. So I added debugging
printlns, and it appears to be getting stuck at the call to
AudioSystem.getAudioFileFormat(URL u)--the statement "Getting audio
format" is never printed. I can't for the life of me figure out what's
going on. As you can see below, I'm catching generic exceptions, so it
can't be an exception that somehow slipped by.
It can't be something wrong with the second file, because I got the
same problem when I tried to get the lines in the opposite order. Does
anyone see anything suspect in the code below/know what could be
causing this problem?
=================CODE=========================
public SourceDataLine line;
public URL url;
public AudioInputStream stream;
public StreamingSound(String url) throws
MalformedURLException,
UnsupportedAudioFileException
{
this.url = new URL(url);
try {
stream = AudioSystem.getAudioInputStream(this.url);
debug("Got an input stream");
}
catch(IOException e) {
e.printStackTrace();
}
debug("About to try getting the line");
try {
debug("Getting file format at URL: " + this.url);
AudioFileFormat fileFormat =
AudioSystem.getAudioFileFormat(this.url);
debug("Getting audio format");
AudioFormat format = fileFormat.getFormat();
debug("Getting DataLine.Info");
DataLine.Info info = new
DataLine.Info(SourceDataLine.class, format);
if (!AudioSystem.isLineSupported(info)) {
System.err.println("Line " + format + " not
supported");
}
try {
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format);
debug("Opened the line");
} catch (LineUnavailableException e) {
System.err.println("Line not available.");
e.printStackTrace();
System.exit(0);
}
}
catch(IOException e) {
e.printStackTrace();
}
catch(Exception e) {
System.err.println("Exception encountered: " +
e.getMessage());
e.printStackTrace();
}
}
===========================================