You can do this very easily using JAudioTagger:
Tag tag; java.util.logging.Logger.getLogger("org.jaudiotagger").setLevel(Level.OFF); audioFile = AudioFileIO.read(new File(filePath)); System.out.println("Track length = " + audioFile.getAudioHeader().getTrackLength());
This will print the length of the file track in filePath. Logger line - remove a lot of (possibly) unwanted information / debugging entries from JAudioTagger. In addition, JAudioTagger supports retrieving all kinds of tag metadata from different types of audio files (MP3, MP4, WMA, FLAC, Ogg Vorbis), as from embedded files. You can even easily get information about MusicBrainz, but I have not tried this yet. For more information:
http://www.jthink.net/jaudiotagger/examples_read.jsp
Here you can get the jar files:
http://download.java.net/maven/2/org/jaudiotagger/
source share