【发布时间】:2009-03-09 11:55:55
【问题描述】:
以下代码用于在我的 java 小程序中播放声音文件:
public synchronized void play() {
try {
//Here filename is a URL retreived through
//getClassLoader().getResource()
InputStream in = new FileInputStream(filename.getFile());
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
} catch (IOException e) {
e.printStackTrace();
}
当我使用 Eclipse 在本地运行小程序时它可以工作,但如果我尝试将它打包在 .jar 中并在 Web 浏览器中作为小程序运行,它就不起作用。注释掉这段代码使小程序工作。
我应该用什么替换上面的代码,这样它才能在小程序中工作?
【问题讨论】: