class One {
public static void main(String[] arg) {
new One().play();
}
public void play() {
try {
AudioClip clip = Applet.newAudioClip(new URL(
"file:\\C:\\Documents and Settings\\admin\\Desktop\\javabottle-open.wav"));
clip.play();
URL ur = new URL("file:\\C:\\Documents and Settings\\admin\\Desktop\\flute+hrn+mrmba.aif");
clip = Applet.newAudioClip(ur);
clip.play();
Thread.sleep(10000);
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
我没有收到任何异常消息&音频也没有播放。
答案 0 :(得分:1)
这对我有用
public class ClipTest {
public void run() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
InputStream inRequest = this.getClass().getResourceAsStream("batR.wav");
AudioInputStream sound = AudioSystem.getAudioInputStream(inRequest);
DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(sound);
clip.addLineListener(new LineListener() {
public void update(LineEvent event) {
if(event.getType() == LineEvent.Type.STOP) {
event.getLine().close();
System.exit(0);
}
}
});
clip.start();
}
public static void main(String[] args) throws Exception {
ClipTest clipTest = new ClipTest();
clipTest.run();
}
}