Java中的循环音乐

时间:2014-04-25 23:39:08

标签: java swing audio javasound

我正试图让这个程序无限循环播放这首歌,但我只是设法让它工作一次。有什么建议吗?

这是我的代码:

public static void music(){

    String filename = "darkAura.wav";
    ContinuousAudioDataStream loop = null;
    InputStream in = null;
    try {
        in = new FileInputStream(filename);
    } catch (FileNotFoundException ex) {
        System.out.println("File not found");
    }
    try {
        AudioStream s = new AudioStream(in);
        AudioData MD;
        AudioPlayer.player.start(s);
    } catch (IOException ex) {
        System.out.println(ex.getMessage());
    }

}

1 个答案:

答案 0 :(得分:2)

您根本没有使用loop变量。 试试这样:

AudioStream s = new AudioStream(in);     
AudioData audiodata = s.getData();
loop = new ContinuousAudioDataStream(audiodata);
AudioPlayer.player.start(loop);