所以我有这个代码应该播放音频文件。尽管编译得很好并且运行没有错误,但它没有。仅供参考:文件位于源文件夹/扬声器中。
import java.io.File;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class SoundCheck {
public static void main(String[] args) {
File song = new File("test.WAV");
PlaySound(song);
}
static void PlaySound(File Sound) {
try {
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(Sound));
clip.start();
Thread.sleep(clip.getMicrosecondLength()/1000);
}
catch (Exception e){
}
}
}