java - Error with playing sounds -


i have faced error playing sounds on button click in java. have field of buttons , if button pressed application plays sound. application throws me exception:

  javax.sound.sampled.lineunavailableexception: unable obtain line 

method , called when button pressed:

public void playsound() {     try {         file file = new file("sounds/sound.wav");         audioinputstream hitstream = audiosystem.getaudioinputstream(file);         audioformat format = hitstream.getformat();         dataline.info info = new dataline.info(clip.class, format);         clip clip = (clip) audiosystem.getline(info);         clip.open(hitstream);         clip.start();     } catch (exception e) {         e.printstacktrace();     } } 

sound play @ beginning crashes. googled exception, found clip should closed after playing sound. thought should add lines after clip.start()

if (!clip.isrunning()) {    clip.stop();    clip.close();         } 

but sounds don't play , whole application start lag. correct solution error?


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -