Xenorosth
Xenorosth

Reputation: 132

Looping Music in Java

I'm trying to get this program to loop the song infinitely, but I've only managed to get it working once. Any advice?

Here is my code:

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());
    }

}

Upvotes: 2

Views: 8926

Answers (1)

vitro
vitro

Reputation: 939

You are not using loop variable at all. Try it like this:

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

Upvotes: 3

Related Questions