Search code examples
javamp3duration

Finding the length of an MP3 file in java, preferably in milliseconds, just like python's mutagen library


Just wanted to know how to perform this since mutagen was very simple and the solutions I have seen for java are very confusing. I am currently using Runtime from java.lang to run the mp3 file but I need the duration of the mp3 file also. Getting the time in miliseconds would be a bonus :D however it isn't that much of an issue converting.

Thanks for your time!

Comarki


Solution

  • There is no simple way to get the playing length of an MP3, the format does not contain a specified "length" anywhere; it was designed with streaming in mind.

    The only way is to parse the MP3 frames and count them, taking into account their sampling rate. This isn't entirely trivial to implement, so using a library is the simplest option: Finding Duration of an MP3 file in Java