【发布时间】:2013-04-09 06:38:21
【问题描述】:
我的应用有问题。当我在 Eclipse 中运行应用程序时,声音播放得很好,但是如果我将应用程序导出到可运行的 jar 中,声音就不起作用了。
方法,播放声音的地方:
public static synchronized void playSound()
{
new Thread(new Runnable()
{
// The wrapper thread is unnecessary, unless it blocks on the
// Clip finishing; see comments.
public void run()
{
try
{
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("sound.wav"));
clip = AudioSystem.getClip();
clip.open(inputStream);
clip.start();
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
}
}).start();
}
哪里可能出错?
【问题讨论】:
-
波形文件是否存在于 JAR 中?
-
我尝试解压jar文件,发现里面有wave文件。
标签: java eclipse audio embedded-resource