Error playing audio file from Java via PulseAudio on Ubuntu

只谈情不闲聊 提交于 2019-11-30 23:36:28
Alessandro Domeneghetti

I solved the problem by simply passing the parameter null into AudioSystem.getClip().

I don't know why this exception occured, I run this project before on Windows, and it worked... After on Linux and here, it didn't work.

I had the same problem and found this code to work:

File soundFile = new File("/home/usr/Desktop/d.wav");
AudioInputStream soundIn = AudioSystem.getAudioInputStream(soundFile);
AudioFormat format = soundIn.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip)AudioSystem.getLine(info);
clip.open(soundIn);
clip.start();
while(clip.isRunning())
{
   Thread.yield();
}

The key is in soundIn.getFormat(). To quote the docs:

Obtains the audio format of the sound data in this audio input stream.

Source: http://ubuntuforums.org/showthread.php?t=1469572

Aaron Digulla

The error message says that the input file format is wrong somehow.

If you gave us more information (file format, maybe where you got it, code that you use to open the file and how you configured the audio drivers), we might be able to help.

See this question for some code that you can try: How to play .wav files with java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!