如何用java读/写ID3v2标签? [英] How to read/write ID3v2 tags with java?

查看:63
本文介绍了如何用java读/写ID3v2标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从 mp3 文件中读取 ID3v2 标签.我找到了多个允许我获取基本标签的框架.但我希望能够加入这个列表.我不关心与 IDv1 的向后兼容性.

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.

我已经看过 Jaudiotaggermp3agic.我没有找到如何将它们用于自定义标签.这可能吗?

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

推荐答案

您必须使用字符串标识符TXXX",这是普通"字段和自定义字段之间的主要区别.我认为以下代码应该是不言自明的:

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") 

这是一种方法.列表现在包含带有 TXXX 标识符的所有标签.现在你可以简单地对列表中的每个元素调用 toString() ,你应该得到一些类似的东西:

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" 

这篇关于如何用java读/写ID3v2标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆