我写了一个程序来播放鸟的声音。我启动它时没有错误,但没有声音。我正在运行 Netbeans IDE。有什么想法或解决方案吗?
这是我的代码:
package JavaFactoryPatternExample;
import java.io.File;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class TutorialSound {
public static void main(String[] args ){
File Bird = new File("JavaFactoryPatternExample.sounds/bird.WAV");
PlaySound(Bird);
}
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){
}
}
}