Error playing java sound (No compatible interface) Supported Clip format)

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(); /** * we can't yet open the device for ALAW/ULAW playback, convert * ALAW/ULAW to PCM */ 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) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (LineUnavailableException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static Music getPlayer() { if (player == null) { player = new Music(); } return player; } public void update(LineEvent event) { } public void stopClip() { clip.stop(); } public void closeClip() { clip.close(); } public void startClip() { clip.start(); } public void volume(float volume) { /* FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(-50.0f); // Reduce volume IN DECIBELS clip.start(); */ } } 

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?

+4
source share
2 answers

In fact, you can play sound above 40 mb, if necessary, how far I went: p, the problem is mainly an eclipse, or rather its folder. metadata in your workspace. I think this is like a small plugin that receives only half the time, so the problem is that your editor, not the code, the code above works fine, since I could play songs without problems. Make sure your paths are correct and try to get the correct version of .metadata and everything should be in order. My friend had the same problem, and I gave him a copy of the workspace and metadata, and it worked perfectly.

+1
source

I experienced the same problem on a raspberry pi. It will play the first 5 files and I will get an error. It turned out that I did not close the clip when I needed.

 Clip clip = AudioSystem.getClip(); clip.addLineListener(event -> { if(LineEvent.Type.STOP.equals(event.getType())) { clip.close(); } }); ByteArrayInputStream audioBytes = new ByteArrayInputStream(SOUNDS.get(file)); AudioInputStream inputStream = AudioSystem.getAudioInputStream(audioBytes); clip.open(inputStream); clip.start(); 

After adding the line listener and closing the clip when it stopped, the errors disappeared.

+1
source

All Articles