I am developing an application in Java. Part of it includes playing an mp3
file via another application. I need to find the duration (total play time) of the mp3
file. How do I do that?
how do i find out duration/total play time of an mp3 file using java?
3k views Asked by shibi vb At
2
There are 2 answers
0
On
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());
That will print out the track length of the file at filePath. The logger line is to remove a lot of (probably) unwanted info/debugging logging from JAudioTagger. Besides this, JAudioTagger supports getting all sorts of metadata tags from different audio file types (MP3, MP4, WMA, FLAC, Ogg Vorbis), both from file-embedded tags. You can even get MusicBrainz info easily, but I haven't tried that yet. For more info:
http://www.jthink.net/jaudiotagger/examples_read.jsp
You can get the jar files for it here:
For small
.mp3
files you can use:This will give a string containing the minute and second duration in it. eg:
316
for3:16
.Note that This method is not suitable with larger files.