java - Could not play a sound in swing -


i trying play .wav file everytime press button.

i've put resource in workspace, project. wrong?

i error message:

javax.sound.sampled.audioinputstream@341bdd4c /home/fred/workspace/projekt/src/gui/sound/gangnam.wav java.lang.illegalargumentexception: invalid format

here code:

public static void main (string [] args) {     jframe customboardframe = new jframe("custom size.");     customboardframe.getcontentpane().add(new customsize());         customboardframe.setdefaultcloseoperation(jframe.exit_on_close);     customboardframe.setsize(450, 310);     customboardframe.setvisible(true);     customboardframe.setresizable(false); } 

public class customsize extends jpanel implements actionlistener {      jbutton playbutton = new jbutton(" >> play <<");     jbutton stopbutton = new jbutton(" >> stop <<");     jbutton pausebutton = new jbutton(" >> pause <<");      public customsize(){          setlayout(null);          playbutton.setbounds(12, 173, 116, 40);         add(playbutton);          playbutton.addactionlistener(this);         pausebutton.addactionlistener(this);         stopbutton.addactionlistener(this);          stopbutton.setbounds(140, 173, 117, 40);         add(stopbutton);          pausebutton.setbounds(269, 173, 140, 40);         add(pausebutton);      }      public void actionperformed(actionevent e){          if (e.getsource().equals(playbutton)) {              try {                 string soundname = "gangnam.wav";                     audioinputstream audioinputstream = audiosystem.getaudioinputstream(new file(soundname).getabsolutefile());                 system.out.println(audioinputstream);                 system.out.println(new file (soundname).getabsolutepath());                 clip clip = audiosystem.getclip();                 clip.open(audioinputstream);                 clip.start();             } catch (exception e1) {                 system.out.println("error.");             }          }         if (e.getsource().equals(stopbutton)) {             system.out.println("stop music.");         }         if (e.getsource().equals(pausebutton)) {             system.out.println("pause music.");         }      } } 

my first step in trying solve manually inspect properties of wav file itself. in windows, can right-click , select properties. then, there second tab has things bit rate , fps.

java can support 44100 fps, , 16-bit encoding. there daws now, though, produce wav files @ 48000 or 96000 fps, or @ 24-bit or 32-bit encoding. java not support these currently, afaik.

if have such file, can modify acceptable format (stereo, 16-bit, 44100fps) program audacity, free download. make sure home site. first time downloaded it, popuppalooza several hours until able rid of crapware came with. home site download (see wikipedia link) should fine.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -