We are trying to integrate sound into one of our projects, my team members do not get this error, and I get it on two different machines.
Stack trace:
Exception in thread "SoundPlayer" java.lang.IllegalArgumentException: No line matching interface Clip supporting format PCM_SIGNED 16000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian, and buffers of 11129272 to 11129272 bytes is supported. at javax.sound.sampled.AudioSystem.getLine(Unknown Source) at sound.Music.run(Music.java:86) at java.lang.Thread.run(Unknown Source)
Code:
package sound; import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.DataLine; import javax.sound.sampled.FloatControl; import javax.sound.sampled.LineEvent; import javax.sound.sampled.LineListener; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; public class Music implements LineListener, Runnable { private File soundFile; private Thread thread; private static Music player; private Music audio; private Clip clip; public Music() { } public void playSiren(String musicFileName) { Music p = getPlayer(); p.playSirenFile(musicFileName); } private void playSirenFile(String musicFileName) { this.soundFile = new File("Music/"+musicFileName+".wav"); thread = new Thread(this); thread.setName("SoundPlayer"); thread.start(); } public void run() { try { AudioInputStream stream = AudioSystem.getAudioInputStream(this.soundFile); AudioFormat format = stream.getFormat(); if ((format.getEncoding() == AudioFormat.Encoding.ULAW) || (format.getEncoding() == AudioFormat.Encoding.ALAW)) { AudioFormat tmp = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), format.getSampleSizeInBits() * 2, format.getChannels(), format.getFrameSize() * 2, format.getFrameRate(), true); stream = AudioSystem.getAudioInputStream(tmp, stream); format = tmp; } DataLine.Info info = new DataLine.Info(Clip.class, stream .getFormat(), ((int) stream.getFrameLength() * format .getFrameSize())); clip = (Clip) AudioSystem.getLine(info); clip.addLineListener(this); clip.open(stream); clip.start(); try { thread.sleep(99); } catch (Exception e) { } while (clip.isActive() && thread != null) { try { thread.sleep(99); } catch (Exception e) { break; } } clip.loop(99999999); } catch (UnsupportedAudioFileException e) {
We call this class from domainController with
audio = new Music(); audio.playSiren("stillAliveDecent");
Does anyone have any ideas how this exception can be resolved? I tried reinstalling my editor software (Eclipse), but to no avail.
Thanks in advance in advance.
Edit
We just tried to switch the sound file. We tried to run it with a much smaller file. now it works, but as soon as we get back to the larger .wav file (10 + MB), I will get an exception again.
Only the use of small files is not really an option, since we would like to use some of our own songs, which are quite long.
Edit 2
I am pretty sure that this is not corrupted wav. we recompiled it, even used another wave of the same length and size, and I'm still the only one who got this error.
Additional Information:
OS: Windows 7 64bit Ultimate
JDK: 1.6.0_22
Edit 3
After creating and reproducing the waves, we came to the conclusion that for some reason I canβt play in a wave larger than 2 MB.
But why didn't my teammates get hurt?