title: Playing .mp3 and .wav in Java?
body: <p>How can I play an <code>.mp3</code> and a <code>.wav</code> file in my Java application? I am using Swing. I tried looking on the internet, for something like this example:</p>
  
  <pre><code>public void playSound() {
      try {
          AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("D:/MusicPlayer/fml.mp3").getAbsoluteFile());
          Clip clip = AudioSystem.getClip();
          clip.open(audioInputStream);
          clip.start();
      } catch(Exception ex) {
          System.out.println("Error with playing sound.");
          ex.printStackTrace();
      }
  }
  </code></pre>
  
  <p>But, this will only play <code>.wav</code> files.</p>
  
  <p>The same with:</p>
  
  <p><a href="http://www.javaworld.com/javaworld/javatips/jw-javatip24.html" rel="noreferrer">http://www.javaworld.com/javaworld/javatips/jw-javatip24.html</a></p>
  
  <p>I want to be able to play both <code>.mp3</code> files and <code>.wav</code> files with the same method.</p>