I know this problem has been queried previously, and I have looked at the responses and tried to implement them, but so far nobody's solutions seem to be working for me. Please can anyone have a look at my code and help me figure out why the program ends instantly, and no sound is played....? thanks in advance
import javax.sound.sampled.*;
import java.io.*;
import java.net.URL;
public class SoundPlayer {
public SoundPlayer() {
}
public static void play(String file) {
File sound = new File(file);
try {
String url = sound.toURI().toURL().toString();
System.out.println(url);
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(new URL(url)));
clip.start();
clip.loop(Clip.LOOP_CONTINUOUSLY);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SoundPlayer player = new SoundPlayer();
player.play("sounds/1.wav");
}
}