Well, specifically, why this code here doesn't seem to want开发者_如何转开发 to play the second audio file:
public static void main(String[] args) {
//Plays first file for a few seconds
playMusic(new File("C:\\sample.wav"));
wait(5.0);
System.out.print("...");
//Second file that doesn't want to play:
playMusic(new File("C:\\sample2.wav"));
}
public static void playMusic(File Stream) {
AudioInputStream AIS
= AudioSystem.getAudioInputStream(Stream);
Clip music = AudioSystem.getClip();
music.open(AIS);
music.start();
}
I figure I have to dismiss something or other (e.g. music.close(), AIS.close()), but these particular examples don't seem to have any effect. Any ideas?
Is it possible your application terminates before your audio clip has finished playing? You may find this SO answer helpful.
精彩评论