How to read/write ID3v2 tags with java?

大憨熊 提交于 2021-02-08 05:10:25

问题


I want to be able to read ID3v2 tags from mp3 files. I have found multiple frameworks which allow me to get the basic tags. But I would like to be able those in this list. I don't care about backwards compatibility with IDv1.

I already had a look at Jaudiotagger and mp3agic. I didn't find out how to use them for custom tags. Is this possible?


回答1:


You've to use the string identifier "TXXX", that's the main difference between "normal" and custom fields. I think the following code should be self-explanatory:

AudioFile audioFile = AudioFileIO.read(File songFile) // try and catch

MP3File mp3 = (MP3File) audioFile;                    
AbstractID3v2Tag v2Tag = mp3.getID3v2Tag();          

// Since you've mentioned a list
List<TagField> tagList = v2Tag.getFields("TXXX") 

That's one way to do it. The List has now all tags with the TXXX identifier. Now you can simply call toString() on every element in the list and you should get something along those lines:

Description="Play Count"; Text="1.000.000" 


来源:https://stackoverflow.com/questions/41459061/how-to-read-write-id3v2-tags-with-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!