使用MP3SPI:
private static void getDurationWithMp3Spi(File file) throws UnsupportedAudioFileException, IOException { AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(file); if (fileFormat instanceof TAudioFileFormat) { Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties(); String key = "duration"; Long microseconds = (Long) properties.get(key); int mili = (int) (microseconds / 1000); int sec = (mili / 1000) % 60; int min = (mili / 1000) / 60; System.out.println("time = " + min + ":" + sec); } else { throw new UnsupportedAudioFileException(); }}


