import java.io.File;
import java.io.IOException;
class Learning {
public static void main(String[] args)
throws SecurityException, IllegalStateException,
UnsupportedAudioFileException,
IOException, LineUnavailableException {
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(
new File("D:\\jaVA items\\BabyElephantWalk60.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.start();
}
}
This is the code , I wanted the file to be played infinite. Actually I am a beginner so I thought doing things practically will be a greater choice . I admit that I copied some lines of code from some different webs. If there are any alternatives for this thing , playing sounds , please tell me . Thanks in Advance !!!!!!!!!!!!
You need to add Thread.sleep(60000)
at the end. Then correct the compilation errors and you are good to go.
It works for me.
The problem with your attempt is that your application (as written) is starting the clip playing in a background (daemon) thread and then immediately exiting. Java exits when all non-daemon threads have ended. In your app, the thread running main
is the only non-daemon thread.
Next, you need to circle back and read the javadocs for the classes / methods that you are using. It is all very well copying some code from the internet to get started ... but you also need to understand what the code you copied it is actually doing.