SOLVED
There was a problem with Runnable, so there were acually TWO game threads running at the same time. (Equals problem!) So the second thread that hit the audio player made the error, and thats why it sounded echoy- it was playing from two different threads!
I also am using SourceDataLine, as suggested, to enable longer sound clips.
Original post-
When this code fires, an error pops up saying
IllegalStateException: Mixer is already open
at the clip.open()
line. I have put in every measure to check if the code is being ran twice, it is not. However, even with the error, the sound still plays. On longer clips (30 seconds) it sounds like theres 2 sounds playing, one right after the other. On REALLY long clips (3 minutes) the sound stutters.
(stringFile
is a String
, such as "example.wav"
)
File soundFile = new File(stringFile);
AudioInputStream inputStream = AudioSystem.getAudioInputStream(soundFile);
AudioFormat format = inputStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
clip = (Clip) AudioSystem.getLine(info);
clip.open(inputStream);
clip.start();
playing = true;
If this question was already posted, I am very sorry. I have searched and I found no thread similar to this one.