【发布时间】:2014-12-15 12:55:48
【问题描述】:
我正在尝试播放一个 .wav 文件。我正在使用此代码:
public static synchronized void play(String path) {
try {
URL soundUrl = SoundTools.class.getResource(path);
AudioInputStream stream = AudioSystem.getAudioInputStream(soundUrl);
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
代码在一段时间内运行良好,但在播放大约 30 次后,我得到了 javax.sound.sampled.LineUnavailableException。错误消息显示unable to obtain a line。我认为这与系统资源有关,但我不知道如何修复它。
【问题讨论】:
-
@Marv 我同意,它们看起来很相似,但是我的错误消息是
unable to obtain a line,而他的错误消息是line with format...