java - Buzzing on Exit -


i'm trying build game uses sound effects. haven't dealt java api before may making mistakes. said though, effects work great — my problem strange buzzing sound maybe second whenever program exits.

any idea how might rid of it? right i'm trying kill playing sounds before exit takes place killloop() method, isn't getting me anywhere.

i'd appreciate help!

public class sound { private audioinputstream audio; private clip clip;  public sound(string location) {     try {             audio = audiosystem.getaudioinputstream(new file(location));             clip = audiosystem.getclip();             clip.open(audio);         }          catch(unsupportedaudiofileexception uae) {             system.out.println(uae);         }         catch(ioexception ioe) {             system.out.println(ioe);         }         catch(lineunavailableexception lua) {             system.out.println(lua);         } }  public void play() {     clip.setframeposition(0);     clip.start(); }  public void loop() {     clip.loop(clip.loop_continuously); }  public void killloop() {     clip.stop();     clip.close(); } }  public class athenaeum { public static void main(string[] args) throws ioexception {     final game game = new game();     gui athenaeumgui = new gui(game);      athenaeumgui.setsize(gui.frame_width, gui.frame_height);     athenaeumgui.settitle("athenaeum");     athenaeumgui.setdefaultcloseoperation(jframe.do_nothing_on_close);     athenaeumgui.setlocationrelativeto(null);     athenaeumgui.setminimumsize(new dimension(gui.frame_width, gui.frame_height));     athenaeumgui.buildgui();     athenaeumgui.setvisible(true);      athenaeumgui.addwindowlistener(new windowadapter() {         public void windowclosing(windowevent we)         {             game.killaudio(); // method calls sound.killloop()             system.exit(0);         }     }); }  } 

in java api, audioinputstream class has ".close()" method "closes audio input stream , releases system resources associated stream". maybe can try.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -