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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -