tags:

views:

66

answers:

2

Hey,

I wonder how I can read out the duration of an mp3 song. If I'm right it's not an ID3 Tag so I guess I have to calculate it somehow ? For the rest of the ID3 Tags I'm using this libary: http://javamusictag.sourceforge.net/index.html

Cheers

A: 

Use some MP3 library. The MP3 format is not that easy that there is some simple way to read out the length of a song.

Sjoerd
Well I'm already using JLayer
Timothy
+1  A: 

You could try using MP3SPI which is based on JLayer. The following code will then allow you to get the song duration:

File file = new File("filename.mp3");
AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file);
Map properties = baseFileFormat.properties();
Long duration = (Long) properties.get("duration");

You can also use MP3SPI to get at the ID3 tags which might save you an extra dependency.

Simon