audio - Playing .wav continuously in java: Invalid Format Exception -


i want play .wav file continuously in java. found code, can't make work.

string filename = "res/sound/buz.wav"; file file = new file(filename); audioinputstream ais; try {     clip clip = audiosystem.getclip();     ais = audiosystem.getaudioinputstream(file);     clip.open(ais);     clip.loop(clip.loop_continuously);  } catch (unsupportedaudiofileexception | ioexception         | lineunavailableexception e) {     e.printstacktrace(); } 

i invalid format exception on clip.open(ais):

exception in thread "main" java.lang.illegalargumentexception: invalid format     @ org.classpath.icedtea.pulseaudio.pulseaudiodataline.createstream(pulseaudiodataline.java:142)     @ org.classpath.icedtea.pulseaudio.pulseaudiodataline.open(pulseaudiodataline.java:99)     @ org.classpath.icedtea.pulseaudio.pulseaudiodataline.open(pulseaudiodataline.java:283)     @ org.classpath.icedtea.pulseaudio.pulseaudioclip.open(pulseaudioclip.java:402)     @ org.classpath.icedtea.pulseaudio.pulseaudioclip.open(pulseaudioclip.java:453)     @ launcher.launcher.main(launcher.java:59) 

i checked , file created correctly , exists. so, problem code?

if matters, i'm working on linux, should work on both linux , windows...

so found solution

    try{         file file = new file (filename);         audioclip clip = applet.newaudioclip(file.tourl());         clip.loop();         clip.stop();     }     catch(exception e){         e.printstacktrace();     } 

i can play .wav file in loop , stop it. that's wanted. , code short.


Comments