audio - Java - How do I load a .wav from inside the jar? -


this question has answer here:

i've been trying play .wav file in java project , got working....or thought. when exported executable jar file, sounds won't play unless they're in same directory jar file. want load sounds inside of jar file. here's code i'm using right now:

    void playsound(string filename) {         try (inputstream in = getclass().getresourceasstream(filename)) {             try (audioinputstream audioin = audiosystem.getaudioinputstream(in)) {                 clip clip = audiosystem.getclip();                 clip.open(audioin);                 clip.start();             }          } catch (exception e) {            e.printstacktrace();        }     } 

i needed change to:

void playsound(string filename) {         try (inputstream in = getclass().getresourceasstream(filename)) {             inputstream bufferedin = new bufferedinputstream(in);             try (audioinputstream audioin = audiosystem.getaudioinputstream(bufferedin)) {                 clip clip = audiosystem.getclip();                 clip.open(audioin);                 clip.start();             }         } catch (exception e) {            e.printstacktrace();        }     } 

but got solution here: java.io.ioexception: mark/reset not supported


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

excel vba - VBA Proxy auto-configuration for http requests -

php - phpWord - Tables with borders in headers/footers -