How do I repeatedly play a wav file?
Printable View
How do I repeatedly play a wav file?
How are you playing it once? Code please.
Code:try
{
File soundFile1 = new File("C:\\won.wav");
if (!soundFile1.exists())
{
System.err.println("Wave file(s) not found!");
return;
}
AudioInputStream audioIn1 = AudioSystem.getAudioInputStream(soundFile1);
// Get a sound clip resource.
playing = AudioSystem.getClip();
// Open audio clip and load samples from the audio input stream.
playing.open(audioIn3);
// Play the file
playing.start();
}
catch (javax.sound.sampled.LineUnavailableException e)
{
e.printStackTrace();
return;
}
catch (Exception e)
{
e.printStackTrace();
return;
}
Try using the Clip methods setLoopPoints(0,-1) and loop(LOOP_CONTINUOUSLY) on playing.
Could you please elaborate?
As I tried it out, I only need to put the "playing.loop(...)". And that'd solve the problem. Correct?
I've never used AudioSystem.getClip() so I can't really elaborate. You will know if it solves the problem by replacing playing.start() with the other two methods I posted before. My reading of the API docs is that both are needed. (I've always used the Applet method getAudioClip() and the AudioClip method loop() - whether in an applet or not.)