title: How do I get a mp3 file's total time in Java?
body: <p>The answers provided in <a href="https://stackoverflow.com/questions/3009908/how-do-i-get-a-sound-files-total-time-in-java">How do I get a sound file’s total time in Java?</a> work well for wav files, but not for mp3 files.</p>
  
  <p>They are (given a file):</p>
  
  <pre><code>AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
  AudioFormat format = audioInputStream.getFormat();
  long frames = audioInputStream.getFrameLength();
  double durationInSeconds = (frames+0.0) / format.getFrameRate();  
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
  AudioFormat format = audioInputStream.getFormat();
  long audioFileLength = file.length();
  int frameSize = format.getFrameSize();
  float frameRate = format.getFrameRate();
  float durationInSeconds = (audioFileLength / (frameSize * frameRate));
  </code></pre>
  
  <p>They give the same correct result for wav files, but wrong and different results for mp3 files.</p>
  
  <p>Any idea what do I have to do to get the mp3 file's duration?</p>