Play wave file using AudioFormat in java

I get the following exception when running my code on Linux operating system. This code works great on the Windows operating system. The following is the exception and the code used.

java.lang.IllegalArgumentException: Missing string matching interface. Supported PCM_SIGNED format supported. Unknown sampling rate, 16 bit, stereo, 4 bytes / frame, large end support.

AudioFormat format = sourceaudio.getFormat(); format = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), format.getSampleSizeInBits() * 2, format.getChannels(), format.getFrameSize() * 2, format.getFrameRate(), true); AudioFileFormat.Type targettype = AudioFileFormat.Type.WAVE; AudioInputStream targetaudiostream = AudioSystem.getAudioInputStream(format, sourceaudio); sourceaudio.close(); targetaudiostream.close(); System.out.println("55555555"); URL url = new URL("http://localhost:8084/newvideo/PCMfile.wav"); Clip clip = AudioSystem.getClip(); AudioInputStream ais = AudioSystem.getAudioInputStream(url); clip.open(ais); System.out.println("seconds: " + (clip.getMicrosecondLength() / 1000000)); 
+4
source share
1 answer

I have the same error for windows when audio devices are disabled in the "device manager". I think the problem is the audio device driver, try updating or reinstalling it.

0
source

Source: https://habr.com/ru/post/1311591/


All Articles