If you are using a larger application, this answer may not apply. But for a simple test, only with this piece of code this can help:
Clip.loop () starts its own thread, but this thread does not support JVM. Therefore, to make it work, make sure that the clip is not the only thread.
If I left Thread.sleep (..) from this fragment, I get the same problem as you;
import java.io.File; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; public class Snippet { public static void main(String[] args) throws Exception { AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("notify.wav")); Clip clip = AudioSystem.getClip(); clip.open(inputStream); clip.loop(Clip.LOOP_CONTINUOUSLY); Thread.sleep(10000);
Paaske
source share