I am trying to make the background music for a game. For some reason, after the song is played for the first time it won't play again. What am I doing wrong and how can i fix it? I know i can use .loop() but i want it to repeat forever, and .loop() will eventually stop.
public class playSong
extends Thread
{
Clip clip=null;
playSong()
{
start();
}
@Override
public void run()
{
while(true)
{
if(clip==null)
{
playSound("fax.wav");
}
else if(!clip.isRunning())
{playSound("fax.wav");}
}
}
public void playSound(String name)
{
try {
File file=new File(this.getClass().getResource(name).getFile());
AudioInputStream audio = AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(audio);
clip.start();
} catch (Exception e) {
System.out.print(e.getMessage());
}
}
}