1
下面的代码工作完全在Windows上:Java的声音可以完美运行在Windows,Linux中我们得到了LineUnavailableException
File soundFile = new File("bell.wav");
AudioInputStream ais = AudioSystem.getAudioInputStream(soundFile);
Clip clip = AudioSystem.getClip();
clip.open(ais);
clip.setFramePosition(0);
clip.start();
Thread.sleep(clip.getMicrosecondLength()/1000);
clip.stop();
clip.close();
但它是导致javax.sound.sampled.LineUnavailableException
例外,在Linux启动时:
No protocol specified
xcb_connection_has_error() вернул true
Home directory not accessible: Отказано в доступе
No protocol specified
javax.sound.sampled.LineUnavailableException
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openImpl(PulseAudioMixer.java:714)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:588)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:584)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.open(PulseAudioMixer.java:579)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:94)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:283)
at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:402)
at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:453)
at beans.SoundDriver.PlayText(SoundDriver.java:41)
请,任何想法,有什么不对?
在Windows中,在哪个目录是运行此应用程序?另外,你的Linux环境中的'bell.wav'在哪里?我所知道的是'bell.wav'是一个Windows系统声音(如果内存正确地为我服务)。 – 2015-02-05 15:32:42
nope。 wav是一种标准音频格式,而不是Windows特定的 – Steffen 2015-02-05 15:38:58
您是否检查过运行java程序的权限?尝试使用管理员权限运行它。 – sphinks 2015-02-05 15:54:25