我知道有this method,但是文档说该文件将转换为目标格式。我既不想转换任何东西,也不想让JRE“尝试”并在每次播放音频文件时确定音频格式。如何在没有此开销的情况下播放音频文件?顺便说一句,该文件是.wav
。
最佳答案
我曾尝试过一段时间。声音格式为.wav
您可以尝试一次...
public static synchronized void audioPlay(String fileLoc) {new Thread(new Runnable() {
public void run() {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream ais= AudioSystem.getAudioInputStream(
Main.class.getResourceAsStream("the path of the wav file" + fileLoc));
clip.open(ais);
clip.start();
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println(ex.getMessage);
}
}
}).start();
}
关于java - 如果我知道音频文件的确切格式并需要重复播放,该如何在Java中播放声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38351513/