开发者

Read out Time/Length/Duration of an Mp3 song in Java

I wonder how I can read out th开发者_运维知识库e 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


I would change the code to...

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

using MP3SPI to use new MpegAudioFileReader() instead of AudioSystem, because i was getting an UnsupportedAudioFileException occured : file is not a supported file type with mp3 files


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜