简体   繁体   English

为什么Java无法播放我的.wav文件?

[英]Why won't java play my .wav files?

Here is my very short test method: 这是我的简短测试方法:

public static void main(String[] args) {

try{
File sound = new File("./res/bird.wav");
AudioInputStream stream = AudioSystem.getAudioInputStream(sound);
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();

Thread.sleep(clip.getMicrosecondLength() / 1000);
}catch (Exception e){
    e.printStackTrace();
}}}

I get no errors, however the file doesn't play. 我没有收到任何错误,但是该文件无法播放。 I've tested with multiple different wav files, but none of them have been playing? 我已经测试了多个不同的wav文件,但是没有一个在播放?

EDIT: Could it be something to do with me being on linux? 编辑:可能与我在linux上有关吗? Pulseaudio does not show any sound output. Pulseaudio不显示任何声音输出。 Also, I'm using Eclipse. 另外,我正在使用Eclipse。

FIXED! 固定!

Apparently PulseAudio and java don't get along by default. 显然,默认情况下PulseAudio和Java不相处。

Here is how I fixed it: 这是我的解决方法:

http://0110.be/posts/PulseAudio_Support_for_Sun_Java_6_on_Ubuntu http://0110.be/posts/PulseAudio_Support_for_Sun_Java_6_on_Ubuntu

Replace java6 with the current version, however. 但是,用当前版本替换java6。 Started working as soon as I copied the jars. 复制瓶子后就开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM