The code
import javax.sound.sampled.*;
import java.io.*;
public class Tester {
static Thread th;
public static void main(String[] args) {
startNewThread();
while( th.isAlive() == true) {
System.out.println("sound thread is working");
}
}
public static void startNewThread() {
Runnable r = new Runnable() {
public void run() {
startPlaying();
}
};
th =new Thread(r);
th.start();
}
public static void startPlaying() {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(new File("d:/UnderTest/wavtester.wav"));
Clip clip = AudioSystem.getClip();
clip.open(ais);
clip.loop(-1); // keep playing the sound
} catch(Exception exc) {
System.out.println(exc);
}
}
}
This code does give the output sound thread working , but does not play anything. In this code i have started a separate thread for playing sound and the program should not terminate till the sound thread has finished it's job .But the program terminates after printing series of sound thread working.
What is the reason for this ( for the program terminating and the sound not playing) ?
clip
has finished. But i don't know the reason why it finishes after 3-4 seconds of playing. – DialecticsJOptionPane
appears for a while and disappears on it's own. I had posted this question before but didn't get any meaningful answer #6595421 – DialecticsJOptionPane
appears for a while and disappears on it's own." The only thing I can think of that would explain that is "Your Java installation is broken". – Elstan