audio - How can I play sound in Java? -
i want able play sound files in program. should look?
i wrote following code works fine. think works .wav
format.
public static synchronized void playsound(final string url) { new thread(new runnable() { // wrapper thread unnecessary, unless blocks on // clip finishing; see comments. public void run() { try { clip clip = audiosystem.getclip(); audioinputstream inputstream = audiosystem.getaudioinputstream( main.class.getresourceasstream("/path/to/sounds/" + url)); clip.open(inputstream); clip.start(); } catch (exception e) { system.err.println(e.getmessage()); } } }).start(); }
Comments
Post a Comment