play sound with java code example
Example 1: How to play sounds on java
void playSound(String soundFile) {
File f = new File("./" + soundFile);
AudioInputStream audioIn = AudioSystem.getAudioInputStream(f.toURI().toURL());
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
clip.start();
}
Example 2: how to play an audio in java
AudioInputStream input = new AudioInputStream(Path_to_the_file);
Clip clip=AudioSystem.geClip();
clip.open(input);
Clip.loop(Clip.LOOP_CONTINUOSLY);
clip.start();