开发者

Second audio clip does not play.

开发者 https://www.devze.com 2023-04-02 02:40 出处:网络
Well, specifically, why this code here doesn\'t seem to want开发者_如何转开发 to play the second audio file:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消