mercredi 24 décembre 2014

How to repeat audio file in java

How would i get the audio file to repeat continuously? Right now the music just plays once and that;s it. I am trying to get the sound to repeat over and over. Would I have to get the audio file another way or is there a simpler way?


Code:



import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

public class Sound {
public static void music(String fileName) {
try {
InputStream in = new FileInputStream(new File(fileName));
AudioStream audioStream = new AudioStream(in);
AudioPlayer.player.start(audioStream);
} catch (IOException e) {
e.printStackTrace();
}
}
}


How i call it:



// Plays the music.
public void music() {
Sound.music("res/music/I Like Your Hat.wav");
}

Aucun commentaire:

Enregistrer un commentaire