Handling the ID3v2 tag
Leave feedback
ID3v2 is a metadata standard that is primarily used with mp3 files. Although it bears the name ID3, its structure is very different from ID3v1. ID3v2 tags consist of a number of frames, each of which contains a piece of metadata.
NoteFor more information on the ID3v2 standard visit http://id3.org/id3v2.3.0. Please note there are three versions of ID3v2: ID3v2.2, ID3v2.3, ID3v2.4.
The GroupDocs.Metadata API allows reading the ID3v2 tag in an MP3 audio. To get more information about ID3 tags, visit: https://en.wikipedia.org/wiki/ID3
The following steps show how to read the ID3v2 tag in an MP3 file.
- Load an MP3 file
- Extract the root metadata package
- Get the ID3v2 tag by using the Mp3RootPackage.getID3V2 method
- If the ID3v2 tag is not null then check for all of its metadata properties
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.MP3WithID3V2)) {
MP3RootPackage root = metadata.getRootPackageGeneric();
if (root.getID3V2() != null) {
System.out.println(root.getID3V2().getAlbum());
System.out.println(root.getID3V2().getArtist());
System.out.println(root.getID3V2().getBand());
System.out.println(root.getID3V2().getTitle());
System.out.println(root.getID3V2().getComposers());
System.out.println(root.getID3V2().getCopyright());
System.out.println(root.getID3V2().getPublisher());
System.out.println(root.getID3V2().getOriginalAlbum());
System.out.println(root.getID3V2().getMusicalKey());
if (root.getID3V2().getAttachedPictures() != null) {
for (ID3V2AttachedPictureFrame attachedPicture : root.getID3V2().getAttachedPictures()) {
System.out.println(attachedPicture.getAttachedPictureType());
System.out.println(attachedPicture.getMimeType());
System.out.println(attachedPicture.getDescription());
// ...
}
}
// ...
}
}
The GroupDocs.Metadata API supports updating the ID3v2 tag in an MP3 audio file.
The following are the steps to update the ID3v2 tag in an MP3 file.
- Load an MP3 file
- Extract the root metadata package
- Create the ID3v2 tag if it’s missing
- Update ID3v2 fields using the Mp3RootPackage.getID3V2 method
- Save the changes
The following code snippet shows how to update the ID3v2 tag in an MP3 file.
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.MP3WithID3V2)) {
MP3RootPackage root = metadata.getRootPackageGeneric();
if (root.getID3V2() == null) {
root.setID3V2(new ID3V2Tag());
}
root.getID3V2().setAlbum("test album");
root.getID3V2().setArtist("test artist");
root.getID3V2().setBand("test band");
root.getID3V2().setTrackNumber("1");
root.getID3V2().setMusicalKey("C#");
root.getID3V2().setTitle("code sample");
root.getID3V2().setDate("2019");
// ...
metadata.save(Constants.OutputMp3);
}
To remove the ID3v2 tag from an MP3 audio just pass null to the Mp3RootPackage.setID3V2 method as a parameter. The code sample below shows how to remove the ID3v2 tag from an MP3 file.
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.MP3WithID3V2)) {
MP3RootPackage root = metadata.getRootPackageGeneric();
root.setID3V2(null);
metadata.save(Constants.OutputMp3);
}
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full featured Java library we provide simple, but powerful free Apps.
You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.