Reputation: 1191
I'm trying to use JAudioTagger in a media player like application to yoink the meta data for each song, but I don't see a field for track duration. I'm sure there must be one but I can't seem to find it and a couple searches haven't turned up anything. I'm looking at: http://www.jthink.com/jaudiotagger/tagmapping.html and at the java docs.
Does anyone have any idea? Thank you for any help!
Upvotes: 1
Views: 3057
Reputation: 803
I can recommend mp4parser library since it returns duration with expected precision (like ffmepg does).
Upvotes: 0
Reputation: 13120
As the earlier answer said the track length is not stored in the tag but can be derived from the audio itself, this is why it is accesible via the audioheader object rather than the tag itself i.e.
AudioFile audioFile = AudioFileIO.readFile("/somefile.mp3");
System.out.println(audioFile.getAudioHeader().getTrackLength());
If it is an mp3, you can all get the tracklength output nicel formatted as mm:ss
System.out.println((Mp3AudioHeader)audioFile.getHeader().getTrackLengthAsString());
or
new MP3File("/somefile.mp3").getMP3AudioHeader().getTrackLengthAsString();
Upvotes: 10
Reputation: 2515
For most formats, the length isn't in the tag.
Many libraries (and media players), like TagLib, estimate it for you by working out the length in seconds of a few hundred kilobytes of the file (the bitrate) and multiplying up. Sometimes this goes horrendously wrong, but, a surprising portion of the time, it works out fine.
Upvotes: 2